If the file has more than one account and one of the account is doing deposit. After deposit, the program only save the changes for the account that doing deposit and other account will be deleted.
How to solve the problem?
Code:
case 'D':
acctType=men.typeMenu();
if(acctType=='C')
{
int acNo,found=0,i;
double bal1,bal2;
system("cls");
r.open("checking.txt");
cout<<"\nDeposit into checking account";
cout<<"\nEnter your checking account number: ";
cin>>acNo;
i=-1;
while(!r.eof()) {
i=i+1;
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;
}
}
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;