C++ Question... Storing data in a .txt?

Hello everyone! I am creating a Money Management program in C++, and I have a question.

I have:
int AccountValue;

Now, currently AccountValue is changed by inputting a number when prompted to by the program, but I want to be able to save the value for later use.

So here is the steps I want the program to take:

1 - Program Starts
2 - Program Reads AccountValue.txt and then sets int AccountValue == whatever is written in AccountValue.txt
3 - User inputs data as to subtract or add to the program
4 - User says "Close Please"
5 - Program edits AccountValue.txt and then saves it for next use.


CURRENT CODING:
--------------------------------------…

#include <iostream>
using namespace std;
int AccountValue;
int AddFunds;
int SubtractFunds;
int a;






int main()
{
cout << "Hello, Welcome to <EGTH>'s BMS (Bank Management System)!" << endl;
cout << "\n\n\nYour account currently has " << AccountValue << " dollars" << endl;
cout << "\nWhat would you like to do?" << endl;
cout << "1. Add Funds" << endl;
cout << "2. Subtract Funds" << endl;
cout << "3. Quit" << endl;
cin >> a;
switch (a)
{
case 1:
cout << "How many dollars to add?" << endl;
cin >> AddFunds;
cout << "New Balance: " << (AccountValue = AccountValue + AddFunds) << endl;
cout << "Main Screen? (1=Yes/2=No)" << endl;
cin >> a;
if (a == 1)
{
main();
}
if (a == 2)
{
cout << "Goodbye!" << endl;
return 0;
}
else if (a != 1, 2)
{
cout << "That wasn't an option, going to main screen." << endl;
main ();
}
break;
case 2:
cout << "How many dollars to subtract?" << endl;
cin >> SubtractFunds;
cout << "New Balance: " << (AccountValue = AccountValue - SubtractFunds) << endl;
cout << "Main Screen? (1=Yes/2=No)" << endl;
cin >> a;
if (a == 1)
{
main();
}
if (a == 2)
{
cout << "Goodbye!" << endl;
return 0;
}
if (a != 1, 2)
{
cout << "That wasn't an option, going to main screen." << endl;
main ();
}
break;
case 3:
cout << "Goodbye!" << endl;
return 0;
break;
default:
cout << "That wasn't an option, going to main screen." << endl;
return 0;
}
}
Also, use code tags.
Topic archived. No new replies allowed.