Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ please: An ATM allows a customer to withdraw a maximum of $500 per day. If a

ID: 3690329 • Letter: C

Question

C++ please: An ATM allows a customer to withdraw a maximum of $500 per day. If a customer withdraws more than $300, the service charge is 4% of the amount over $300. If the customer does not have sufficient money in the account, the ATM informs the customer about the insufficient funds and gives the customer the option to withdraw the money for a service charge of $25.00. If there is no money in the account or if the account balance is negative, the ATM does not allow the customer to withdraw any money. If the amount to be withdrawn is greater than $500, the ATM informs the customer about the maximum amount that can be withdrawn. Write an algorithm that allows the customer to enter the amount to be withdrawn. The algorithm then checks the total amount in the account, dispenses the money to the customer, and debits the account by the amount withdrawn and the service charges, if any.

Explanation / Answer

main.cpp


#include <iostream>
using namespace std;

int main(int argc, const char * argv[]) {
    const double MAX_WITHDRAWAL_PER_DAY = 500.0;
    double customerAccount = 0.0;
    double withdrawal      = 0.0;
    double serviceCharge   = 0.0;
  
    // set initial amount
    cout << "Set the current amount in your accont: ";
    cin >> customerAccount;
    cout << endl;
  
    // Welcome message and show current amount
    cout << "Welcome to Bank" << endl;
    cout << "You have $" << customerAccount << " in your account." << endl;
    cout << endl;
  
    // Return if there is no money in the customer's account
    if (customerAccount <= 0) {
        cout << "You have no money in your account." << endl;
        cout << "Good-bye." << endl;
        return 0;
    }
  
    // User inputs the amount of withdrawal
    cout << "How much do you want to withdraw? (example: 30.00): ";
    cin >> withdrawal;
    cout << endl;
  
    // Check if customer has enough money for this withdrawal
    if (customerAccount < withdrawal) {
        cout << "You don't have enough money in your account." << endl;
        cout << "If you really want money, you can proceed by paying a service fee of $25.00." << endl;
        cout << "Do you want to pay $25.00 and proceed? (Y/N): ";
        char userChar = '?';
        cin >> userChar;
      
        switch (userChar) {
            case 'Y':
            case 'y':
                serviceCharge += 25.0;
                cout << "Thank you." << endl;
                break;
            default:
                cout << "Good-bye!!!" << endl;
                return 0;
        }
    }
  
    // Service charge of 4% when withdrawal is greater than 300.
    if (withdrawal > 300.0) {
        cout << "There will be service charge of 4% of the amount over $300." << endl;
        cout << "Do you want to proceed? (Y/N): ";
        char userChar = '?';
        cin >> userChar;
      
        switch (userChar) {
            case 'Y':
            case 'y':
                serviceCharge += (withdrawal - 300.0) * 0.04;
                cout << "Thank you." << endl;
                break;
            default:
                cout << "Good-bye!!!" << endl;
                return 0;
        }
    }
  
    // Enforce MAX_WITHDRAWAL_PER_DAY.
    if (withdrawal >= MAX_WITHDRAWAL_PER_DAY) {
        withdrawal = MAX_WITHDRAWAL_PER_DAY;
    }
  
    // Process the withdrawal
    customerAccount = customerAccount - withdrawal - serviceCharge;
  
    // check total amount in account, withdrawal, debit, service charges
    cout << "You withdrew:                   $" << withdrawal << endl;
    cout << "Service charges:                $" << serviceCharge << endl;
    cout << "--------------------------------------" << endl;
    cout << "Updated amount in your account: $" << customerAccount << endl;
    cout << endl;
    cout << "Thank you for using bank. See you later!" << endl;
  
    return 0;
}


sample output

                                                                                                                                                            
Welcome to Bank                                                                                                                                      
You have $1000 in your account.                                                                                                                             
                                                                                                                                                            
How much do you want to withdraw? (example: 30.00): 500                                                                                                     
                                                                                                                                                            
There will be service charge of 4% of the amount over $300.                                                                                                 
Do you want to proceed? (Y/N): y                                                                                                                            
Thank you.                                                                                                                                                  
You withdrew:                   $500                                                                                                                        
Service charges:                $8                                                                                                                          
--------------------------------------                                                                                                                      
Updated amount in your account: $492                                                                                                                        
                                                                                                                                                            
Thank you for using bank. See you later!                                                                                                               

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote