i need to make a c++ console based program for a banking system using files. i implemented some code but having difficulty with withdrawing money from the account, checking balance, transferring funds and viewing transaction.
For withdrawing funds i implemented the following code but it doesn't seem to work properly. (To withdraw i need to ask the user to enter a name and from that i need to search the file from that right?)
Thank you very much in advance. Been stuck with this for a long time:(
void withdraw(){
int accountNo;
string name,_name;
double amount,withdrawal;
string answer;
string line = "";
cout<<"**Withdraw Cash**"<<endl;
ifstream cashfile("cashfile.txt");
cout<<"Please Enter account Number:"<<endl;
cin>>accountNo;
cout<<"Please Enter Name"<<endl;
cin>>name;
cout<<"Please Enter amount to withdraw Rs:";
cin>>withdrawal;
while (getline(cashfile,line)) {
stringstream pop(line);
pop>>_name;
cashfile>>accountNo>>name>>amount;
amount = ::total - withdrawal;
ofstream cashfile;
cashfile.open("cashfile.txt",ios_base::trunc); //Discard the file’s contents
cashfile<<accountNo<<" "<<name<<" "<<amount<<" "<<endl;
cout<<"Amount withdrawal Successful"<<endl;
cout<<"Balance is Rs" << amount <<endl;
}
}