You might want to reconsider your design. The function returns the current players health, but you start with an intialization. This should be done somewhere else. The only thing this function should do is return and display the current health quantifier.
int setCurPlayerHealth()
{
curPlayerHealth = maxPlayerHealth;
return curPlayerHealth;
}
That's still not working. curPlayerHealth and maxPlayerHealth are both global.
The only reason why I made it a function is because maxPlayerHealth is set in a function before the currentPlayerHealth. Therefore since I'm setting curPlayerHealth to maxPlayerHealth, I need to set the variable before the currentPlayerHealth and after the function PlayerHealth() where maxPlayerHealth is defined.
Why not set current health equivent to max health in the same function where it's first defined? I mean, I don't understand why you need to set player health to max every time you want to query player health.
int currentPlayerHealth(int curPlayerHealth)
{
cout << "Current health: " << curPlayerHealth << endl;
cout << endl;
return curPlayerHealth; // not really needed since its value is the same
// as when the function was called
}
int main()
{
int maxPlayerHealth = 100;
int curPlayerHealth = maxPlayerHealth;
curPlayerHealth -= 30;
currentPlayerHealth(curPlayerHealth);
cin.get(); // to prevent the console from closing
The problem is, my maxPlayerHealth is randomly generated inside it's own function. The point is, it's random and so therefore I can't set it. Probably would have been better to mention that before :P