Hi guys, have a school project that i am working on but i am just running into this one problem. Well its not really a problem its more of a me just starting the c++ course and i just wanted to do something extra to get some more marks. We had to make a bank ATM program which would be liek the real thing, i decided that instead of defining the balance, i would have it read from a txt file and from there i could read/write to it. We haven tlearned this in class but i thought i would give it a shot.
I just wanted to know how i would add/subtract from a txt file? Say the user wants to withdraw 400$ out of the 500$ that the txt contains. How would i do this?(i know formating is off, i pasted it into google docs from school to open it at home)
ya so i would appreciate it if someone could tell me how i would go about adding/withdrawing from my txt file.
here is some of my code.
//BANK ATM PROGRAM.
#include <fstream>
#include <iostream>
using namespace std;
int main ()
{
double pass = 0;
double choice;
int acc1;
int acc2;
int amount;
int deposit;
cout<<"Please enter you PIN code"<<endl;
cin>>pass;
if (pass == 5555)
cout<<"PIN VALIDATED...."<<endl;
do
{
if (pass != 5555)
{
cout<<"Please enter you PIN Again code"<<endl;
cin>>pass;
}
}while( pass != 5555);
system("cls");
while(pass == 5555)
{
cout<<"__________________________________________________________________________"<<endl;
cout<<" ATM MACHINE "<<endl;
cout<<"__________________________________________________________________________"<<endl;
cout<<"Please pick one of the below options..."<<endl;
cout<<"amountDRAW FUNDS"<<endl;
cout<<"DEPOSIT"<<endl;
cout<<"TRANSFER"<<endl;
cout<<"CHECK BALANCE"<<endl;
cout<<"CLOSE"<<endl;
cin>>choice;
if (choice == 1)
{
{
cout<<" PLEASE PICK AN ACCOUNT"<<endl;
cout<<"1) ACCOUNT ONE: "<<endl;
cout<<"2) ACCOUNT TWO: "<<endl;
cin>>acc1;
}
}
if (choice == 1 && acc1 == 1)
{
{
system("cls");
cout<<"____________________________"<<endl;
cout<<" ACCOUNT ONE" <<endl;
cout<<"____________________________"<<endl;
char bank [200];
fstream file_op("G:\\bank.dat",ios::in);
while(file_op >> bank)
cout<<"BANK BALANCE FOR ACCOUNT "<<bank<<"$"<<endl;
file_op.close();
if (acc1 == 1)
cout<<"HOW MUCH WOULD YOU LIKE TO WITHDRAW"<<endl;
cin>>amount;
}
}
if (choice == 1 && acc1 == 2)
{
{
system("cls");
cout<<"____________________________"<<endl;
cout<<" ACCOUNT TWO" <<endl;
cout<<"____________________________"<<endl;
char bank2 [200];
fstream file_op("G:\\bank2.dat",ios::in);
while(file_op >> bank2)
cout<<"BANK BALANCE FOR ACCOUNT "<<bank2<<"$"<<endl;
system("pause");
system("cls");
file_op.close();
if (acc1 == 2)
cout<<"HOW MUCH WOULD YOU LIKE TO WITHDRAW"<<endl;
cin>>amount;
}
}
if (choice == 2)
{
char bank1 [200];
fstream file_op("G:\\bank1.dat",ios::in);
while(file_op >> bank1)
cout<<"ACCOUNT ONE"<<bank1<<endl;
cout<<"HOW MUCH TO DEPOSIT"<<endl;
cin>>deposit;
file_op.close();
}
system("pause");
return 0;
}
}