Classwork 9: Amortization Table

Objectives

To practice using for loops.

The Assignment

For this assignment, you will write a program that prints out an amortization table for a car loan.

Suppose that you buy a new car for \$20,000 with a 48 month loan at 4.5% interest. You can go to a website like Bankrate.com and use their auto loan calculator to find out that the monthly payment of the loan is \$456.07. This is actually not too hard to calculate. You can just use the formula:

payment = ( i × P ) / [ 1 − ( 1 + i)−n ]

where i is the monthly interest (in decimal, not as a percentage), P is the principal (the original loan amount) and n is the number of months. For now, we will just use the \$456.07 from the auto loan calculator.

For this assignment, you must write a program that uses a for loop to print out the amortization table. This table shows how much you owe on your car after each month. The first few rows of the table might look like:

```
Interest   Principal
Month    paid       paid     Balance
1      75.00     381.07    19618.93
2      73.57     382.50    19236.43
3      72.14     383.93    18852.50

```

These figures are computed as follows. First, we need the monthly interest rate. This is simply the annual interest rate divided by 12:

4.5% ÷ 12 = 0.375% = 0.00375
So, the interest on the original \$20,000 for the first month is:

\$20000 × 0.00375 = \$75

Thus, of the \$456.07 monthly payment, \$75 goes towards interest and the remaining \$456.07 - 75 = \$381.07 goes towards paying down the principal. The balance on the loan at the end of the first month is:

\$20000 − 381.07 = \$19618.93

Similarly, interest at the end of the second month is \$19618.93 × 0.00375 = \$73.57, which leaves \$456.07 − 73.57 = \$382.50 to pay down the principal. Thus, the balance becomes \$19618.93 − 382.50 = \$19236.43.

Your program should make these calculations inside a for loop and print out all 48 months of the amortization table. At the end of 48 months of paying \$456.07 per month, the balance should be \$0.

Notes

• You can print out just 2 decimal places after the decimal point using %.2f in your printf statements.

• You can check your answer on Bankrate.com by clicking on "Show/Recalculate Amortization Table".

• If you are done early, you can embellish your program by adding a feature that asks the user for the original loan amount, the annual interest rate and the number of months in the loan. Then, use the formula shown above to compute the monthly payment. (You will need to use the pow() function from the math library for exponentiation. See Classwork 5.)

What to submit

Use the script command to record yourself compiling and running your program. (Do not record yourself editing your program!) Exit from script. Submit your program and the typescript file:

```
submit cs104_chang cw09 table.c typescript

```