Tuesday, November 22, 2016

Programming Challenge 4.14 - Bank Charges

/* Bank Charges - A bank charges $10 per month plus the following check fees for a
   commercial checking account:

   * $.10 each for fewer than 20 checks
   * $.08 each for 20 to 39 checks
   * $.06 each for 40 to 59 checks
   * $.04 each for 60 or more checks

   The bank also charges an extra $15 if the balance of the account falls below
   $400 (before any check fees are applied).

   This program asks for the beginning balance and the number of checks written.
   It computes and displays the bank's service fees for the month.

   Input Validation: Negative values on checks written are not accepted. If a
   negative value is given for the beginning balance, an urgent message is being
   displayed indicating the account is overdrawn. */

#include "Utility.h"

int main()
{
    /* Constant for minimum account balance with normal service charge */
    const double MIN_ACC_BALANCE = 400;

    /* Constants for monthly normal and extra charges */
    const double NORMAL_CHARGE = 10.0;
    const double EXTRA_CHARGE = 15.0;

    /* Hold beginning balance and current balance */
    double beginningAccBalance = 0,
           currentAccBalance = 0;

    /* Hold number of checks */
    int numChecks;

    /* Hold service fees, check fees, and total fees */
    double serviceFee = 0,
           checkFee = 0,
           totalFees = 0;

    /* Ask the user for his or her beginning account balance */
    cout << "Enter your beginning account balance $";
    cin >> beginningAccBalance;

    /* Determine whether additional charges apply because the account balance is
    below $400 and the beginning account balance is in the positive */
    if (beginningAccBalance < MIN_ACC_BALANCE)
    {
        currentAccBalance = (beginningAccBalance - NORMAL_CHARGE - EXTRA_CHARGE);

        cout << "Your current account balance is less than $" << MIN_ACC_BALANCE
            << " Additional charges of $" << NORMAL_CHARGE
            << " and $" << EXTRA_CHARGE << " extra charge were deducted.\n"
            << "Your account balance is $" << currentAccBalance << endl;
    }
    else
    {
        currentAccBalance = (beginningAccBalance - NORMAL_CHARGE);

        cout << "Your account balance is $" << currentAccBalance << endl;
    }

    if (beginningAccBalance <= 0)
    {
        cout << "WARNING! Your account is overdrawn!\n";
    }
    else
    {
        /* Ask the user for number of checks */
        cout << "\nHow many checks have you written this month? ";
        cin >> numChecks;

        /* Formating the output */
        cout << fixed << showpoint << setprecision(2);

        /* Determine how many additional fees must be added based upon number of
           checks written */
        if (numChecks > 0 && numChecks < 20)
        {
            serviceFee = currentAccBalance - (numChecks * .10);
            cout << "You have written " << numChecks << " checks this month\n"
                << "A fee of $" << .10 << " has been deducted.\n";
            cout << "Your current account Balance is $" << serviceFee << endl;
        }
        else if (numChecks >= 20 && numChecks <= 39)
        {
            serviceFee = currentAccBalance - (numChecks * .08);
            cout << "You have written " << numChecks << " checks this month\n"
                << "A fee of $" << .08 << " has been deducted.\n";
            cout << "Your current account balance total is $" << serviceFee << endl;
        }
        else if (numChecks >= 40 && numChecks <= 59)
        {
            serviceFee = currentAccBalance - (numChecks * .06);
            cout << "You have written " << numChecks << " checks this month\n"
                << "A fee of $" << .06 << " per check has been deducted.\n";
            cout << "Your current account balance total is $" << serviceFee << endl;
        }
        else if (numChecks >= 60)
        {
            serviceFee = currentAccBalance - (numChecks * .04);
            cout << "You have written " << numChecks << " checks this month\n"
                << "A fee of $" << .04 << " per check has been deducted.\n";
            cout << "Your current account balance total is $" << serviceFee << endl;
        }
        else
        {
            cout << "The amount of checks written must be greater than 0.\n";
        }
    }

    pauseSystem();
    return 0;
}

No comments:

Post a Comment