Even worse are functions that reference global variables, though. Have you used pointers? If not try this:
Code:
void double(int * health){
*health *= 2;
}
void halve(int * health){
if(*health)
*health /= 2;
}
int main(){
int some_health = 12;
cout << "Health: " << some_health << endl;
double(&health);
cout << "Doubled: " << some_health << endl;
halve(&health);
cout << "Halved: " << some_health << endl;
cin.get();
return 0;
}
You could use references too which allow you to make permanant changes to the variable but using non-pointer syntax:
Code:
void double(int& health){
health *= 2;
}
void halve(int& health){
if(health)
health /= 2;
}
int main(){
int some_health = 12;
cout << "Health: " << some_health << endl;
double(health);
cout << "Doubled: " << some_health << endl;
halve(health);
cout << "Halved: " << some_health << endl;
cin.get();
return 0;
}
Hope that helps...