CODE WARS ]I[ PROGRAMMING COMPETITION
That's Amoré!
Problem 8 Division I / II 9 Points
Problem Statement
Loan payments are calculated according to a non-homogeneous linear recurrance relation. The balance owed on a loan is called principal. The charge for the borrowed money is called interest, and it is calculated as a percentage of the principal. Interest is typically published according to an annual rate, although it may be charged on a monthly basis.
     If we let P be the initial loan principal, and let R be the annual interest rate, and let N be the number of months over which the loan is to be repaid, then we can calculate the monthly payment M according to the following formula:
     Each month when a loan payment is made, therefore, a portion of the payment is applied to interest while the remainder is applied to principal. If the principal balance in month n is Pn, then the interest amount levied that month is (R/12) * Pn. Banks and tax accountants are keenly interested (heh, heh) in knowing how much money each month is applied to each category.
     Write a program to calculate loan payments and display an amortization schedule.
Program Input
The input file PROG08.IN will contain the initial principal amount, the annual interest rate, and the number of months of the loan period, in that order. Each number will be on a separate line as in the example below. There will be no blank lines.
     The program does not need to validate the unit labels that appear after the numbers, but it should simply skip them. The dollar amount can range from $10000 to $99999. The interest rate may be within the range 6.0% to 18.0%. (Remember that 7.25% is a common representation of the number 7.25 / 100). The loan period may vary from 12 to 60 months.

12000.00 Dollars
7.25%
12 Months
Program Output
The program should write PROG08.OUT with three sections of information: 1) the monthly payment for the loan, 2) the amortization table, and 3) total interest and total amount paid. The amortization table must show, for each month, the amount of payment amount applied to interest and principal, plus the final balance. All dollar amounts should be rounded to cents*, and these amounts ABSOLUTELY MUST line up the decimal point in each column. Misaligned decimal points will cause the answer to be judged as incorrect!

* Tracking monetary rounding errors is a problem of its own, so for this problem we won't be concerned about rounding errors less than 3 cents.

for a loan of $12000.00, borrowed for 12 months at an annual interest rate of 7.25%, the monthly payment is $1039.70.
month  interest principal balance
  1      72.50    967.20   11032.80
  2      66.66    973.05   10059.75
  3      60.78    978.93    9080.82
  4      54.86    984.84    8095.98
  5      48.91    990.79    7105.19
  6      42.93    996.78    6108.41
  7      36.90   1002.80    5105.61
  8      30.85   1008.86    4096.75
  9      24.75   1014.95    3081.80
 10      18.62   1021.09    2060.71
 11      12.45   1027.25    1033.46
 12       6.24   1033.46       0.00
total interest paid:     476.45
total amount paid:   12476.45