I cant figure out why i keep getting an error message but it says the varible "gold" was not declared in this scope, here is a peice of my script
gold=0;
total_gold=gold+total_gold;
string work;
cin >> work;
if (work=="yes" or "Yes"){
cout << "You just gained 10 gold!" << endl;
cout << "You now have " << gold << endl;
cout << "Do you want to go back to work or to the store?"<< endl;}
string store; cin >> store;
if (store=="yes" or "Yes")
{cout << "Would you like to buy an apple?" << endl;}
string apples; cin >> apples;
if (apples=="yes" or "Yes"){}
22|error: 'gold' was not declared in this scope|
||=== Build finished: 1 errors, 0 warnings ===|
this isnt all of my script but its where the error is located at
does anyone know how to fix this error?
I'm a beginner as well, so I may be talking below you here but.. did you declare "gold" earlier as an int? Otherwise, sometimes my IDE doesn't realize I've changed something, and compiles a previous version of my code. My computer is pretty old. I quit and open it again and it usually works.
You should try declaring the "gold" and "total_gold" before using them,something like:
1 2 3 4
int gold,total_gold;
/* or int gold;
int total_gold+=gold;*/
//or however you feel using amongst
Take note that where you said
if (work=="yes" or "Yes"),you might wanna change that to: if (work=="Yes" || work="yes"),I am not saying the use of "or" and "||" are different,BUT its just better of that way.