I am writing a code for Banking system and got stuck and am unable to point out what's wrong. Can anyone help me?
This functions was to modify the balance from accounts stored in a binary file 'Accounts.bat'. but the loop is never ending.
void transaction :: process()
{ int bflag=0;
if(type==0||type==1)
{ account b;
fstream file("Accounts.bof",ios::binary);
file.seekg(0,ios::beg);
while(!file.eof())
{ file.read((char*)&b, sizeof(b));
if(file.eof())
break;
if(b.get_acno()==payee.ac)
{ if(b.get_balance()>=amount)
{ b.minus_money(amount);
bflag=1;
file.seekp(-1*(sizeof(b)),ios::cur);
file.write((char*)&b, sizeof(b));
b.out(); //to output account's details
getch();
break;
cout<<"Money deducted";
getch();
}
}
file.write((char*)&b, sizeof(b));
}
if(bflag==0)
cout<<"\n\n\t\tTransaction unsuccessful!!!";
cout<<"\n\t\tCause : Insufficient Balance.";
file.close();
}
if(type==0||type==2)
{ account b;
fstream file("Accounts.bof",ios::binary);
while(!file.eof())
{ file.read((char*)&b, sizeof(b));
if(!file.eof())
break;
if(b.get_acno()==recieptent.ac)
{ b.add_money(amount);
cout<<"money added";
file.seekp(-1*(sizeof(b)),ios::cur);
file.write((char*)&b, sizeof(b));
break;
}
file.write((char*)&b, sizeof(b));
}
file.close();
}
if(bflag)
cout<<"\n\n\t\tTransaction successful.";
getch();
}