Skip to main content
added 780 characters in body
Source Link
Angel
  • 33
  • 1
  • 4

I have a problem regarding how the values under a certain parameter doesn't change after being called again.

I have this kind of code, where, an imp (monster) and a character has to go for a battle:

#include <iostream>
using namespace std;

int gems = 0;

float imp (float imphp) {
float implife = imphp - 5.0;
return implife;
};

float character (float charlife) {
float charalives = charlife - 2.0;
return charalives;
};

int main () {
string charactername;
cout << "Hero Life: ";
cout << character(10.0) <<endl;
cout << "Monster Life: ";
cout << imp (10.0) <<endl;

};

My problem or rather a question is if I call the monster function again is that it returns the value as 1.

Code I used to call monster for the second time after the first turns of damage is done:

cout << monster << endl;

what happens there was it sends me a value of 1. how can i make it show the current value after the damage has been taken...? say if the imp takes another damage, how can i make my program show the current value, since if the imp took out 2.0 at first attack, then takes another 2.0, the value for the hp of the character to show is 6.0? Same with the other function, how can i return it to the current value?

I have a problem regarding how the values under a certain parameter doesn't change after being called again.

I have this kind of code, where, an imp (monster) and a character has to go for a battle:

#include <iostream>
using namespace std;

int gems = 0;

float imp (float imphp) {
float implife = imphp - 5.0;
return implife;
};

float character (float charlife) {
float charalives = charlife - 2.0;
return charalives;
};

int main () {
string charactername;
cout

I have a problem regarding how the values under a certain parameter doesn't change after being called again.

I have this kind of code, where, an imp (monster) and a character has to go for a battle:

#include <iostream>
using namespace std;

int gems = 0;

float imp (float imphp) {
float implife = imphp - 5.0;
return implife;
};

float character (float charlife) {
float charalives = charlife - 2.0;
return charalives;
};

int main () {
string charactername;
cout << "Hero Life: ";
cout << character(10.0) <<endl;
cout << "Monster Life: ";
cout << imp (10.0) <<endl;

};

My problem or rather a question is if I call the monster function again is that it returns the value as 1.

Code I used to call monster for the second time after the first turns of damage is done:

cout << monster << endl;

what happens there was it sends me a value of 1. how can i make it show the current value after the damage has been taken...? say if the imp takes another damage, how can i make my program show the current value, since if the imp took out 2.0 at first attack, then takes another 2.0, the value for the hp of the character to show is 6.0? Same with the other function, how can i return it to the current value?

Source Link
Angel
  • 33
  • 1
  • 4

C++ Function Parameter Changes Problem

I have a problem regarding how the values under a certain parameter doesn't change after being called again.

I have this kind of code, where, an imp (monster) and a character has to go for a battle:

#include <iostream>
using namespace std;

int gems = 0;

float imp (float imphp) {
float implife = imphp - 5.0;
return implife;
};

float character (float charlife) {
float charalives = charlife - 2.0;
return charalives;
};

int main () {
string charactername;
cout