0
Why won´t this work? c++
I am making a program where you can either answer "Yes" or "No". There will be different outcomes depending on which option you choose. I also wanted the program to tell the user when they gave the wrong input. My problem is that even if the user types "Yes", the program will still write out "Please type 'Yes or 'No'. Is there anything wrong with the code that I have pasted down below, or do you guys think it has to do with some other part of the program? else if (Answer!="Yes"||Answer!="No") { cout << "Please type 'Yes' or 'No'" << endl << endl; }
10 Answers
+ 2
Added break to exit inner while loop and removed a++ some places.
https://code.sololearn.com/cmBuqsdH0NP5/?ref=app
Hope this helps you!
+ 2
Line no 76 there is an if statement for "Yes"
use else if for "No" and then else for other cases. Currently I'm on mobile can't run this code.
+ 2
Actually it works i tested on online compiler. If you type 'yes' to goes to upgrade part. If 'no' program exit and print final stats.
And if user enter anything other than yes or no else block give them instruction to enter yes or no then wait for user to enter yes or no goes to begining of upgrade part. Am i right?
+ 1
Use else block for that situation.
If (answer ==Yes) {....}
else if answer ==No {...}
else { Please type 'Yes' or 'No'}
+ 1
I just tried it and it seems like the program for some reason always wants to activate that 'else'-statement. I thought that the program would skip over the 'else' if the 'if'-statement was true?
+ 1
I just realised that I forgot to use my brain when running the program. You are completely correct and you have solved the problem completely! Thank you very much for your time and help!
0
I switched the 'else if' into an 'else', but the problem is still there
0
The full code should be public on my profile now. It's called "Fighters"
0
Can't do that. There is no 'if' that comes before the one on line 105. I could change it into a 'else if' if I included the 'if' and 'else' from lines 105 and 109 into the 'while(UP>0)'-loop on line 74. But I don't think the program as a whole would work if I did that
0
Your sollution helped me remove some of the issues, but there are still some concerning the same problem that was in my question. When you get to the "upgrade" part, no matter what you answer it still says "Please type 'Yes' or 'No'". It also takes you back to the "Would you like to upgrade your fighter?" part.