Calculating Debt
As a starving student, you will no doubt have to take out many credit cards
to survive (how else will you be able to afford food, rent, and iPods?).
But after acquiring so many credit cards, you are having difficulty seeing
how much debt you will accumulate. Your task is to write a simple program
to help you see this easier.
Your program is to prompt the user for the following inputs
- How much money you currently have charged on your credit card. Call
this amountCharged.
- What interest rate you have on that credit card. Call this
interestRate. Note that if you have an interest rate of
6%, you'll probably want to represent this as 0.06 (and it's
alright if the user must input the percent as this).
- How many years before you will start paying off the credit card. Call
this numYears. For this, require a positive whole number
(i.e. do not use a float or double to
represent this).
Once you have these inputs, your program is to output the following...
- For each year, output the year number (simply an integer from 1 to
numYears), and how much you'll owe after that year
(including interest).
- After numYears, the total amount that will have accumulated
because of interest on your credit card.
To calculate the amount owed for each year (call the year number simply
year), you must use the following equation
amountOwed = amountCharged * (1 + interestRate)year
Where amountOwed is the amount owed after year year.
NOTE: To calculate powers, such as
xy
You'll want to do the following...
- Include the cmath library in your program, by adding
#include <cmath>
After you include iostream.
- To calculate something like (1 + interestRate)year, do
the following...
pow( 1.0 + interestRate, year )
Below is output from a run of such a program...
Enter the amount charged: 3500
Enter the interest rate as a decmial (E.g. for 6% enter 0.06): 0.07
Enter the number of years before you'll start paying off: 10
Year Amount Owed
---- -----------
1 3745.00
2 4007.15
3 4287.65
4 4587.79
5 4908.93
6 5252.56
7 5620.24
8 6013.65
9 6434.61
10 6885.03
After 10 year(s) you'll owe a total of $6885.03