I'm trying to make a rpgish text based game and when I get to my makeshift combat system (which is a do while loop) after the loop is done it skips if statements that I need it to see. Heres the part of code:
do {
system("CLS");
cout << "You hit the rat for " << PlayerAtk << " damage\n";
cout << "The rat bites you for " << RatAtk << " damage\n";
PlayerHp = PlayerHp - RatAtk;
RatHp = RatHp - PlayerAtk;
cout << "Your hp is " << PlayerHp << " from 50" << endl;
cout << "The rat's hp is " << RatHp << " from 15" << endl;
PlayerAtk = rand() % 5 + 1;
RatAtk = rand() % 3 + 1;
} while (RatHp >= 0 && PlayerHp >= 0);
if (PlayerHp <= 0) {
cout << "You died would you like to play again(yes/no): ";
cin >> choice2;
if (choice2 == "yes") {
system("CLS");
PlayAgain = true;
}
else {
exit(0);
}
}
}
else if(RatHp <= 0) {
cout << "You killed the rat and gained " << Loot << " gold!" << endl;
Gold = Gold + Loot;
cout << "Would you like to go to the main menu(yes/no): ";
cin >> choice3;
do {
system("CLS");
cout << "You hit the rat for " << PlayerAtk << " damage\n";
cout << "The rat bites you for " << RatAtk << " damage\n";
PlayerHp -= RatAtk;
RatHp -= PlayerAtk;
cout << "Your hp is " << PlayerHp << " from 50" << endl;
cout << "The rat's hp is " << RatHp << " from 15" << endl;
PlayerAtk = rand() % 5 + 1;
RatAtk = rand() % 3 + 1;
} while (RatHp > 0 && PlayerHp > 0);
if (PlayerHp <= 0) {
cout << "You died! Would you like to play again(yes/no): ";
cin >> choice2;
if (choice2 == "yes") {
system("CLS");
PlayAgain = true;
}
else {
exit(0);
}
}
} //Useless bracket? If this bracket's extraneous, you just ended your function.
elseif(RatHp <= 0) {
cout << "You killed the rat and gained " << Loot << " gold!" << endl;
Gold += Loot;
cout << "Would you like to go to the main menu(yes/no): ";
cin >> choice3;
}
if (choice3 == "yes") {
PlayAgain = true;
}
else {
exit(0);
}
} //Useless bracket? If this bracket's extraneous, you just ended your function.
You have extra brackets in your code that appear to be ending your function early.
Alright thanks that worked and fixed the problem, sorry about the code thing. The second bracket actually ended the else if rathp function so it isn't useless but the first one ended the rat choice if statement too early. And thanks for the little fixes like the gold thing and the while part of the loop.