All pastes #25824 Raw Edit

Unnamed

public text v1 · immutable
#25824 ·published 2005-10-18 10:44 UTC
rendered paste body
void 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');
        }
    }
}