Use a file to manipulate a variable.

I am doing a school project on making UI for an atm machine. SO my question is how can I use a variable such as 'CURRENTBALANCE' be manipulated by the information in a .txt file then needs to be saved in said .txt file.
I looked at all the lecture notes/code examples and it isn't in there.

#include <iostream>
#include <fstream>
using namespace std;

int main()
{

double CURRENTBALANCE, DEPOSIT;

cout << "How much would you like to deposit?' << endl;
cin >> DEPOSIT;

ofstream myfile;
myfile.open("Balance.txt");
myfile << CURRENTBALANCE + DEPOSIT;
myfile.close();

return 0;
}
Start with
1
2
3
4
ifstream myfile;
myfile.open("Balance.txt");
myfile >> CURRENTBALANCE;
myfile.close();
What if CURRENTBALANCE has not been declared yet?
I guess you detect the failure to open the input file, and assign a value of zero.
Topic archived. No new replies allowed.