rendered paste bodyvoid withdrawFunds(int accountID)
{
fstream file;
file.open("customer.dat");
if (!file)
{
cout << "Error: Cannot open \"customer.dat\" for input." << endl;
return;
}
cout << "Withdrawal amount: ";
float amount;
cin >> amount;
int accountFind;
while (file.eof() == 0)
{
file >> accountFind;
if (accountFind == accountID)
{
file.ignore(30,'\n');
file.ignore(30,'\n');
file.ignore(30,'\n');
float balance;
file >> balance;
if (amount > balance)
{
cout << "Insufficient funds." << endl;
return;
}
balance = balance - amount;
file << balance;
file << "test";
cout << amount << " withdrawn." << endl;
cout << "Your current balance is: " << balance << endl;
file.close();
return;
}
else
{
file.ignore(30,'\n');
file.ignore(30,'\n');
file.ignore(30,'\n');
file.ignore(30,'\n');
}
}
}