Need help with rpg game code

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>

using namespace 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;
              }
    else if (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;
closed account (2UD8vCM9)
Why finalHp and hp?

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.
Last edited on
ya thanks man it worked sorry im really new to this
closed account (2UD8vCM9)
No problem brother just try not to over complicate stuff you know

Edit: Lol on the other note, is your rpg about a serial killer?

YOU SEE A MAN! KILL HIM? XD
Last edited on
Topic archived. No new replies allowed.