void Deposit()
{
int amount, AccNo;
cout << "DEPOSITING MONEY\n";
cout << "Enter your account number first: ";
cin >> AccNo;
cout << "Enter the amount you want to deposit: ";
cin >> amount;
ofstream Temp("temp.bin", ios :: binary);
Account temp;
File.seekg(0);
while(File.eof()){
File.read(reinterpret_cast <char*> (&temp), sizeof(Account));
temp.showData();
int flag = temp.returnAccNo();
if(AccNo == flag)
temp.Deposit(amount);
Temp.write(reinterpret_cast <char*> (&temp), sizeof(Account));
}
Temp.close();
File.close();
remove("Account.bin");
rename("temp.bin", "Account.bin");
cout << "Your deposit has been successfully done. Have a nice day! ";
Sleep(1000);
}
Why this Deposit()
function not working, I don't understand. When this function is called and only two objects have been written into the file, the while loop in this code iterates three times and the last object that is written is written twice. Please help!!