Description
The purpose of this challenge is to use various flow control structures. This challenge uses techniques for displaying formatted output, simulating a payment structure for paying off outstanding debt such as a credit card or any kind of interest-bearing loan.
Requirements
- Declare double variables called balance, monthly, apr, apr_monthly, start_bal, interest, end_bal
- Declare an integer called months
- Prompt the user to enter values for balance, monthly, and apr
- Use a while loop to display the payment breakdown and how long it will take to pay off the balance. We use a while loop since we don’t know how many months it will take based on the input values. This loop will continue to run as long as there is a balance remaining
- Use these formulas to calculate the payment breakdown
- apr_monthly = (apr / 12) / 100
- interest = start_bal * apr_monthly
- end_bal = start_bal + interest – monthly
- end_bal becomes start_bal the following payment cycle
- Include <iomanip> and call cout << fixed << setprecision(2) to format your output
- Use the setw(x) call in your cout stream to format your output. x is an integer indicating the width of the displayed column. For example, setw(5) will set a column width of 5. See below on how to display the table data
cout << setw(5) << months << setw(10) << start_bal ... (of course, you can't actually use ellipses in the code. That's just an indicator that you can continue with whatever data and formatting you need)
- Note that some combination of input values may create an infinite loop, meaning the balance never gets paid off. It can, in fact, increase if the monthly payment cannot cover the interest payment (try balance = 2000, monthly = 25, apr = 24 during your test runs)
Do Not Use
You may not use the break statement to terminate any loops
Sample Interaction / Output
What is the outstanding balance? 2000 What is the APR? 24 How much do you pay every month? 125 The table shows how long it will take to pay: Month Start Interest Monthly End 1 2000.00 40.00 125.00 1915.00 2 1915.00 38.30 125.00 1828.30 3 1828.30 36.57 125.00 1739.87 4 1739.87 34.80 125.00 1649.66 5 1649.66 32.99 125.00 1557.66 6 1557.66 31.15 125.00 1463.81 7 1463.81 29.28 125.00 1368.09 8 1368.09 27.36 125.00 1270.45 9 1270.45 25.41 125.00 1170.86 10 1170.86 23.42 125.00 1069.27 11 1069.27 21.39 125.00 965.66 12 965.66 19.31 125.00 859.97 13 859.97 17.20 125.00 752.17 14 752.17 15.04 125.00 642.22 15 642.22 12.84 125.00 530.06 16 530.06 10.60 125.00 415.66 17 415.66 8.31 125.00 298.97 18 298.97 5.98 125.00 179.95 19 179.95 3.60 125.00 58.55 20 58.55 1.17 125.00 -65.28
LEGEND
PROGRAM OUTPUT
USER INPUT
FROM INPUT
CATALOG ID: CPP-CHAL0002C
Print Requirements