This is my deposit, i want to save the value that is on (currentBalance) to the text file call balance. Right now I only know to store a sentence "Writing this to a file1". I want to write to a new line, not rewrite.
But I want to store only last 3 deposit, because later on, I want to let the use to see the last 3 deposit he did.
float deposit( int y, int x)
{
cout<<"\n"<<endl;
cout<<"Welcome to the deposit area"<<endl;
cout<<"Enter a sum you wish to add to your account:";
cin>> y ;
currentBalance = y + x ;
cout << "Your new balance is:" << currentBalance <<endl;
ofstream myfile;
myfile.open ("balance.txt");
myfile << "Writing this to a file1.\n";
myfile.close();
cout<<"\n"<<endl;
cout<<"Press 0 for further action or press 9 to exit." <<endl;
cin >> option;
if (option == 9)
{
exit(0);
}
else if (option == 0 )
{
return 1;
}
else
{
exit(0);
}
}
How do I store what is on current balance.
This is my balance code.
float balance(int x)
{
cout<<"Welcome to the balance area"<<endl;
cout<< "Your balance is: " <<(char)156 <<endl;
string line;
ifstream myfile ("balance.txt");
if (myfile.is_open())
{
while ( getline (myfile,line) )
{
cout << line << '\n';
}
myfile.close();
}