I am working on a text-based RPG game and every time I run the code, it just repeats the first cout's over and over again. The one thing that it
does that I wanted it to do is when I push the 'n' || 'N' button it does end the game. For some reason I cannot understand why it keeps repeating
like it is.
If anyone can help me and show me what I am doing wrong it would be greatly appreciated. Thank you in advance.
here is my source code:
P.S. I am using NetBeans as my IDE, not sure if that is the issue or not, don't think that it should matter but just thought I would say it anyway.
Your statement at line 54 has a few problems: else(userInput == 'n' || 'N');
1) Missing if
2) Comparison is incorrect. 'n' || 'N' will always evaluate to true.
3) You have a semicolon after the condition which terminates the statement.
It should be: elseif (userInput == 'n' || userInput == 'N')
Thank you very much for pointing out those mistakes, but it is still repeating this line of code:
1 2 3
cout << "This is the story of how the current king came into power." <<endl;
cout << "If at anytime you wish to exit the game, just push the 'q key" <<endl;
cout << "and press <Enter>. Note: Your game will not be saved." << endl;
not sure why it is doing this.
I mean that it is not moving on to this line of code:
1 2 3 4 5 6 7
cin >> userInput;
if(userInput == 'y' || userInput == 'Y')
{
cout << "In this story you will guide the hero to kingship." << endl;
cout << "continue... Yes(y) or No(n)?" << endl;
break;
}
The problem is you are using continue statements incorrectly. When you use continue it skips everything else that is after it inside the loop and goes to the next iteration of that loop if possible (which in this case is just the beginning of your infinite while loop). So it never sees any of the other if statements.
Remove the continues and it should progress normally.