This part has a problem for saving in switch case. After deposit, the file only save the first account and the other account will be deleted.
How to solve this problem?
How to set an error message if account not found or end of file?
Code:
case 'D':
acctType=men.typeMenu();
if(acctType=='C')
{
int acNo;
double bal1,bal2;
system("cls");
r.open("checking.txt");
cout<<"\nDeposit into checking account";
cout<<"\nEnter your checking account number: ";
cin>>acNo;
for(int i=0;!r.eof()+1;i++)
{
r.read((char*)(&che[i]),sizeof(che[i]));
if(acNo==che[i].getacctNum())
{
bal1=che[i].getBal();
cout<<"\n\nFound in "<<i<<endl;
w.open("checking.txt");
che[i].deposit();
w.write((char*)(&che[i]),sizeof(che[i]));
w.close();
bal2=che[i].getBal();
tra[n].setTran(acNo,"Deposit","Success",bal1,bal2);
w.open("transaction.txt",ios::app,ios::ate);
w.write((char*)(&tra[n]),sizeof(tra[n]));
w.close();
break;
}
}
/*if(r.eof())
{
cout<<"\nSorry, no such account.";
cout<<"\n\nPress ENTER to continue...";
while(!cin.get()){};
//while(!cin.get()){};
}*/
r.close();
break;
}
if(acctType=='S')
{
sav[n].deposit();
break;
}
else
{
cout<<"Invalid type";
cout<<"\n\nPress ENTER to continue...";
while(!cin.get()){};
while(!cin.get()){};
}
break;