Calculating interest due

I have coded this as best as I can; but, after writing my else if statement I realized the third component that I have to program won't work properly with what I have. The question is as follows:

Write a program to compute the interest due, total amount due, and the minimum payment for a revolving credit account. The program accepts the account balance as input, then adds on the interest to get the total amount due. The rate schedules are the following: The interest is 1.5 percent on the first $1000, and 1 percent on any amount over that. The minimum payment is the total amount due if that is $10 or less; otherwise, it is $10 or 10 percent of the total amount owed, whichever is larger. Your program should include a loop that lets the user repeat this calculation until the user says she or he is done.

For example:
$1000 balance = 1015 total, $101.50 minimum payment
$50 balance = 50.75 total, $10 Minimum Payment
$1500 balance = 1520 total, $152 minimum Payment

With what I have, it will calculate the 1000 and 1500 amount correctly. Although, I feel there is a better way to code my else if statement. I realized after writing the else if though that if I try to calculate the $50 dollar balance it will not take, and I'm not sure of any other way to do this. I'm thinking maybe to throw a nested if statement inside of the first statement so that it will show the correct minimum payment. When I do the $50 dollar example it says my minimum payment is 5 dollars.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
    cout << "This program will compute the interest due, total amount due, and"
            " the minimum payment for a resolving credit account.";
    cout << " Enter your account balance: ";
    int accountBalance;
    string userInput;
    double balance;
    double balanceOverThousand;
    double interest = 0.015;
    double additionalInterest = 0.01;
    cin >> accountBalance;

        if(accountBalance <= 1000)
        {
            balance = (accountBalance * interest) + (accountBalance);
            cout << accountBalance << " balance = " << balance << " total, $" 
                 << balance / 10 << " minimum payment\n"; 
        }
        else if (accountBalance > 1000)
        {
            balanceOverThousand = ((1000 * 0.015) + 
                    (accountBalance - 1000) * (0.01)) + accountBalance;
            cout << accountBalance << " balance = " << balanceOverThousand <<
                    " total, $" << balanceOverThousand / 10 << " minimum "
                    "payment\n";
        }
        else
        {
            cout << "Invalid input. \n";
        }


I understand that my loop is not yet in place but once I get my if/else if statements working I will implement the loop.
Analysing... 1st thing is that the else {} block will never be called because you handle all numbers <= 1000 and > 1000 which covers everything including negatives...

For 50.00, you're dividing the balance by 10: balance / 10, which will yield 5.075, not 10.00. So if there is a minimum payment, you'll need another if statement as you correctly figured that checks for a minimum payment...

So something like:

balance = (accountBalance * interest) + (accountBalance);
double payment = balance / 10;
if (payment < 10.00)
payment = 10.00;
cout << accountBalance << " balance = " << balance << " total, $" << payment << " minimum payment\n";
Last edited on
One other thing, these variables are not currently being used:

string userInput;
double additionalInterest = 0.01;

I bring it up in the interest of clean code. :)

As an additional hint, if you set a variable to a value that will never be changed, make it const so that you don't accidentally change it.

e.g.: const double interest = 0.015;
Last edited on
Topic archived. No new replies allowed.