After deposit, the program will save the changes of balance, but the saved thing is some funny thing. How to solve the problem?
The funny thing that display on screen:
$4.25248e-311
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();
che[i].deposit();
bal2=che[i].getBal();
tra[n].setTran(acNo,d,m,y,h,t,"Checking","Deposit","Success",bal1,bal2);
w.open("transaction.txt",ios::app,ios::ate);
w.write((char*)(&tra[n]),sizeof(tra[n]));
w.close();
found=1;
}
}
r.close();
w.open("checking.txt");
for(int c=0;c<i;c=c+1)
w.write((char*)(&che[c]),sizeof(che[c]));
w.close();
if(found==0)
{
cout<<"\nSorry, no such account.";
}
cout<<"\n\nPress ENTER to continue...";
while(!cin.get()){};
while(!cin.get()){};
break;
}
if(acctType=='S')
{
int acNo,found=0,i;
double bal1,bal2;
system("cls");
r.open("saving.txt");
cout<<"\nDeposit into saving account";
cout<<"\nEnter your saving account number: ";
cin>>acNo;
i=-1;
while(!r.eof())
{
i=i+1;
r.read((char*)(&sav[i]),sizeof(sav[i]));
if(acNo==sav[i].getacctNum())
{
bal1=sav[i].getBal();
sav[i].deposit();
bal2=sav[i].getBal();
tra[n].setTran(acNo,d,m,y,h,t,"Saving","Deposit","Success",bal1,bal2);
w.open("transaction.txt",ios::app,ios::ate);
w.write((char*)(&tra[n]),sizeof(tra[n]));
w.close();
found=1;
}
}
r.close();
w.open("saving.txt");
for(int c=0;c<i;c=c+1)
w.write((char*)(&sav[c]),sizeof(sav[c]));
w.close();
if(found==0)
{
cout<<"\nSorry, no such account.";
}
cout<<"\n\nPress ENTER to continue...";
while(!cin.get()){};
while(!cin.get()){};
break;
}
else
{
cout<<"Invalid type";
cout<<"\n\nPress ENTER to continue...";
while(!cin.get()){};
while(!cin.get()){};
}
break;