int variable modified by output of another int variable?

Hello I'm trying write a program that will modify an int variable by subtracting the output of another variable.
The problem is I don't know how to make the variables interact.
I am by no means an expert in C++, I know very little, but I have a strong feeling this can be done, I'm just not sure what the exact code is.

Here are the variables

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// I'll post some variables that are referenced in the following variable to
// add context

    int str;
    int dex;
    int con;

    int statmod_str;
    statmod_str = (str - 10) / 2;

    int statmod_dex;
    statmod_dex = (dex - 10) / 2;

    int statmod_con;
    statmod_con = (con - 10) / 2;

// I'm posting this to add context to the reference of the player_health
// variable in the second variable

    int player_health;
    player_health = 20 + (statmod_con * 6);

// These are the two variables in question

    int troll_attack_damage;
    troll_attack_damage = 1+rand()%(8) + troll_str_mod;

// And I need the above variable to interact with the following variable

    int player_current_health;
    player_current_health = player_health - troll_attack_damage;

If someone could help me out, or at least point me in the right direction, it would be much apperciated.
Thanks in advance.
Last edited on
made troll attack damage a function.
1
2
3
4
int trollAttackDamage()
{
    return 1 + rand()%8 + troll_str_mod;
}

And use player_current_health -= trollAttackDamage(); //Decreases current health by troll attack damage
It is better to have 2 variables: current_health and max_health and nothing more.
Last edited on
Thanks for the response MiiNiPaa,

As per your suggestion I created a function to handle the troll's damage, but I placed it before int main()
I'm not exactly sure if that is where it should go, but the program compiled with no errors, so when I finish working out the function I'll test test the program and report my findings.

I also really appreciate you giving me the code to work out player_current_health being affected by the new trollAttackDamage() function.
Topic archived. No new replies allowed.