C++ Multi-Character Character Constant Warning | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

C++ Multi-Character Character Constant Warning

I keep getting a multi-character character constant warning after the 'yes' input in my Game code (I would post it, but my computer doesn't allow me to and I currently can't access my phone). Does anyone know how to fix the error?

16th May 2019, 7:50 PM
Code Babylon
Code Babylon - avatar
6 Answers
+ 3
https://code.sololearn.com/cn0cQAv0oCr0/#cpp ^Here you go. Fixed it up a little for you. Hope that helps. :::INPUT::: AgentSmith Fighter yes :::: OUTPUT ::::: What is your name? Welcome to my world AgentSmith. Pick your class: Fighter Witch Archer You chose Fighter. Is this correct? As a Fighter, your job is to kill as many enemies as possible to rid this world of evil. :::CODE::: #include <iostream> using namespace std; int main() { string playerName; string playerClass; string classConfirm; // Name selection cout << "What is your name?\n"; cin >> playerName; // Greeting cout << "Welcome to my world " << playerName << ".\n\n"; // Class selection ClassMenu: cout << "Pick your class: \n\n" "Fighter\n\n" "Witch\n\n" "Archer\n\n"; cin >> playerClass; cout << "\n"; cout << "\nYou chose " << playerClass << ".\n\n" "Is this correct?\n\n"; cin >> classConfirm; if (classConfirm == "yes") { cout << "As a " << playerClass << ", your job is to kill as many enemies as possible to rid this world of evil.\n"; } else { cout << "Please pick another class.\n"; goto ClassMenu; } return 0; }
16th May 2019, 8:07 PM
AgentSmith
+ 2
Change it from: char input; To: string input; You're getting the error because char is expecting a single char, not a string of chars. Also, I see some logic issues. Create a variable that's storing the selected class, then you can properly display the class name in the message. At the moment you're displaying the value of input, which is simply checking for if you say "yes" to your selection being correct.
16th May 2019, 8:04 PM
AgentSmith
+ 2
You're welcome bro! Hope that helps out some. Best of luck in your learning!
16th May 2019, 8:14 PM
AgentSmith
+ 1
Hard to say without you posting anything at all. Have you tried double quotes instead of single quotes? Can you post that specific lines of the code? Just a matter of copy/paste the line.
16th May 2019, 7:53 PM
AgentSmith
+ 1
AgentSmith Thank you!
16th May 2019, 8:05 PM
Code Babylon
Code Babylon - avatar
0
AgentSmith I have, and it doesn't work. And I did post the code on Code Playground and it's the topmost code on my profile.
16th May 2019, 7:55 PM
Code Babylon
Code Babylon - avatar