I've been teaching myself C++ for the past few hours (I have previous coding experience, but only very basic). I'm wondering, how would I allow the user to change the value of a variable between different functions?
Edit: I do have an intermediate knowledge of Python from school, but it has completely left my mind. I'm basically asking for refreshers, not tutorials. Once I'm reminded, I'll be all set. Sorry for the confusion.
int shop() {
int selection;
cout << "This is the shop!" << endl;
cout << "What would you like to browse?: " << endl;
cin >> selection;
switch (selection) {
case1: {
int selection;
cout << "Farmer Market!\n1) Seeds (T1)\n2) Seeds (T2)\n3) Seeds (T3)\n4) Tools (T1)\n5) Tools (T2)\n6) Tools (T3)" << endl;
cout << "What would you like to buy?: ";
switch (selection) {
case 1: {
items = 1; ///THIS IS THE PART I NEED HELP WITH
}
}
}
}
}
int inventory() {
int items;
int tools;
return items, tools;
How would I allow the user to buy some seeds in the function shop()
, then assign a value of 1
to the items
variable in the function inventory()
, without needing to assign a global variable? I need items
to retain its value throughout the rest of the game.