How to remember Variables?

Hello! I am trying to make a stock simulator, but I want to make the portfolio remember its money, or value, it has. Thank you in advance for whoever helps me!

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126`` ``````//version v.1 #include using namespace std; int main() { int stock; float price; int portfolio=10000; char stockyn; char menu; int choice; cout << "Welcome to Stocking Stocks Simulator! This is your current portfolio: " << portfolio << " Current StockB\$" << endl; cout << "Stock market crash! Inducers are rich!" << endl; cout << "Current stocks, Microsoft: each stock, 120 each."; cout << " Want to buy? Y or N?" << endl; cin >> stockyn; if (stockyn == 'Y') { cout << "Bought one trade! Current portfolio: " << portfolio - 120 << endl; } else if (stockyn == 'N') { cout << "Didn't buy trade, Current portfolio: "<< portfolio << endl; } cout << "Current Stocks, YAHOO, 100 each, "; cout << "Wanna buy? Y or N?" << endl; cin >> stockyn; if (stockyn == 'Y') { cout << "Bought a trade! Current portfolio: " << portfolio - 100 << endl; } else if (stockyn == 'N') { cout << "Didn't buy a trade, current portfolio: " << portfolio << endl; } cout << "What would you like to do next?" << endl; bool stockMenu = true; while (stockMenu != false){ cout << "-----------------" << endl; cout << "1 - Check your portfolio." << endl; cout << "2 - Get a new stock partner." << endl; cout << "3 - Help." << endl; cout << "4 - Exit." << endl; cin >> choice; switch (choice) { case 1: cout << "Current portfolio: " << portfolio << endl; break; case 2: cout << "AOQL, 50 each, wanna buy?"; cout << " Y or N?" << endl; cin >> stockyn; if (stockyn == 'Y'){ cout << "Bought trade! Current portfolio: " << portfolio - 50 << endl; } else if (stockyn == 'N') { cout << "Didn't buy trade, current portfolio: " << portfolio << endl; cout << "Do you want to have another trade partner?" << endl; cin >> stockyn; if (stockyn = 'Y') { cout << "Do you wanna buy AEX? 500 each, Y or N?" << endl; cin >> stockyn; if (stockyn == 'Y') { cout << "Bought! current portfolio: " << portfolio - 500 << endl; } else if (stockyn = 'N') { cout << "Didn't buy, current portfolio: " << portfolio << endl; cout << "Would you like a different trade partner? Y or N." << endl; cin >> stockyn; if (stockyn == 'Y') { cout << "Would you like to buy from TOPAZ? 1000 each. Y or N?" << endl; cin >> stockyn; if (stockyn == 'Y') { cout << "Trade bought! Current portfolio: " << portfolio - 1000 << endl; } else if (stockyn == 'N') { cout << "Trade cancelled, more trades soon!" << endl; } } } } } break; case 3: cout << "Just search up some tutorials lol." << endl; case 4: cout << "Exiting the program.." << endl; stockMenu = false; break; default: cout << "Not a vaild choice." << endl; cout << "Choose again!"; cin >> choice; break; } } return 0; } ``````
variables retain their value until the program ends.
if you want to remember values when the program is not running, you want a disk file.
a simple text file works a lot like cin / cout.

ifstream ifs("filename.txt");
ifs << variable << endl; //write

or
ofstream ofs("filename.txt");