Hi i am new to programming and have just finished a book and a couple vids on c++.
and am making a simple console rpg game. but i can keep this int finalHp to update after every part in the game. so for example when i type in to kill a man it subtracts 15 hp but when it comes to the 3 paths it goes back to 100. i cant find a way to keep it updated so that it subtracts right when another part in the game comes up
#include <iostream>
usingnamespace std;
int main(int argc, char *argv[])
{
string input;
int hp = 100;
int finalHp;
cout <<"Your HP is " <<hp <<endl;
cout <<"You see a man, Would you like to kill him?\n1 Yes\n2 no" << endl;
cin >> input;
if (input == "yes" || input == "Yes"){
finalHp = hp -15;
cout<<"You killed him! You now have " << finalHp << endl;
}
elseif (input == "no" || input == "No"){
cout <<"You decide not to kill him"<< endl;
}
finalHp = hp;
cout <<"Your HP is " << finalHp << endl;
cout <<"You come across 3 paths, which do you choose?\n1 Left\n2 Middle\n3 Right"<< endl;
cin >> input;
Instead of doing finalHP = hp - 15; do finalhp-=15;
The issue is this.
On line 14, you have finalHp = hp - 15. This will set finalHp to 85.
However, if you ever choose "no", your finalHp will be set back to 100 since you have finalHp = hp; and nothing is changing hp which means it'll always be 100.