In my c++ game the rush hour has bugs. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

In my c++ game the rush hour has bugs.

So recently I updated my game: The last textfighter And thanks to David for fixing one of my bugs but in this update I added rush hour and there is also a bug. And I need help from someone to fix it. Bug: In rush hour when I attack the player and even if it's health is less than zero I have to enter invaild characters to stop the game and so please fix it. And you will get featured I promise Here it is: https://code.sololearn.com/cczsWlo0yD29/?ref=app

24th Jan 2020, 6:04 AM
Kirui-kun
Kirui-kun - avatar
4 Answers
+ 2
Your evaluation of ra has nothing to do with ch. Separate the conditional statements. if (ra == "hand") { ... } else if (ra == "foot") { ... } else if (ra == "rage") { ... } else { // invalid input } if (ch <= 0) { // you win } else if (hp <= 0) { // you lose } else if (hp <= 0 && ch <= 0) { // draw } It should be obvious since the conditional statements in your classic mode is structured this way. Perhaps you fixed it there but not in rush mode.
24th Jan 2020, 6:17 AM
Fermi
Fermi - avatar
+ 1
Just a little tip for the next time you program something and you don't want someone to kill you, use variables name more evident, so people who will check your code don't need to think so hard, and....
24th Jan 2020, 7:04 AM
Esteban Chacon Martín
Esteban Chacon Martín - avatar
0
Thanks
24th Jan 2020, 7:07 AM
Kirui-kun
Kirui-kun - avatar
0
if (ch <= 0) { cout << "\nYou won the rush"; break; if (hp <= 0) { cout << "\nYour opponent won"; break; } if (hp <= 0 && ch <= 0) { cout << "draw"; break; } } I don't understand really why is the condition of the player winning inside the opponent winning condition, could be that... try to separate those conditions cause you only will win if the opponent win and that has no much logic, I think...
24th Jan 2020, 7:09 AM
Esteban Chacon Martín
Esteban Chacon Martín - avatar