In my code I have an object which defines a "health value", I want to create a game loop where health is subtracted each time that there is another loop. I find that any variables that are given values within a class are constantly subtracted but with an object its only subtracted and prints the same subtracted value? Is there a fix to this or should I rather find an alternative method?
class card {
public:
int health, att;
char type;
int Ehealth = 100;
char dec;
void battle(int attack, int h)
{
cout << "Pick an action: ";
cin >> dec;
switch (dec) {
case 'A':
Ehealth -= attack;
h -= 5;
break;
}
cout << "The enemy's health is: " << Ehealth << endl
<< "Your health is: " << h << endl;
}
};
int main()
{
card gunther;
gunther.health = 150;
gunther.att = 5;
gunther.type = 'D';
while (1) {
gunther.battle(gunther.att, gunther.health);
}
}
This is the output:
(Pick an action: A
The enemy's health is: 95
Your health is: 145
Pick an action: A
The enemy's health is: 90
Your health is: 145
Pick an action:)
The 145 stays the same when I wanted it to be 140, 135 etc.