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.
// 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.
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.
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.