House (or Car) payment program.
In this assignment, you are to write a program that will compute a
monthly payment.
This assignment is broken up into 2 parts. (1. compute the payment and
2. display an amortization table.)
You are to have, at least, 1 function
( other than main() ) in both programs.
The function(s) must be referenced by the main program.
Part 1
The formula for computing the monthly payment for a long term loan is
shown below.
P * mir
Payment = ---------------------------
--- --- 12*y
| 1 |
1 - | ------- |
| 1 + mir |
--- ---
P Principal
mir interest rate for 1 month
y number of years
The input to the program (from the keyboard) is the Principal (P=70000),
the yearly interest rate (yir=9.5) and the number of years (y=30).
The output is a line exactly like the following:
Principal 70000.00 Interest Rate 9.5000 Years 30.0 Payment 588.60
To solve this problem you can (if you want to) break it up into parts,
then compute each part.
The following table shows the calculations that have to be performed, along
with values for a $70,000 loan at 9.5% over 30 years. You can use these
numbers to check your program.
yir
mir = ----
1200
|
.007916
|
a = 1 + mir
|
1.007916
|
1
b = ---
a
|
.992145514
|
c = 12 * y
|
360
|
c
d = b
|
.058497109
|
e = 1 - d
|
.94150289
|
f = p * mir
|
554.12
|
f
payment = ---
e
|
588.60
|
Part 2
You are to generate and print the first 8 rows and the last 8 rows of a
complete amortization table, very similar to the one shown below (including
the dashes). You are to have (and reference), at least, 1 function (other
than main) in your program.
Sample output:
-------------------------------------------------------------------------
| Principal 70000.00 Interest Rate 9.5000 Years 30.0 Payment 588.60 |
| |
| Month Pay Total Monthly Principal Total Remaining |
| Paid Interest Paid Principal Balance |
| Paid |
| |
| 1 588.60 588.60 554.17 34.43 34.43 69965.57 |
| 2 588.60 1177.20 553.89 34.70 69.14 69930.86 |
| 3 588.60 1765.79 553.62 34.98 104.11 69895.89 |
| 4 588.60 2354.39 553.34 35.26 139.37 69860.63 |
| 5 588.60 2942.99 553.06 35.53 174.90 69825.10 |
| 6 588.60 3531.59 552.78 35.82 210.72 69789.28 |
| 7 588.60 4120.19 552.50 36.10 246.82 69753.18 |
| 8 588.60 4708.78 552.21 36.39 283.20 69716.80 |
| - - - - - - - |
| 353 588.60 207775.07 35.98 552.61 66007.25 3992.75 |
| 354 588.60 208363.67 31.61 556.99 66564.24 3435.76 |
| 355 588.60 208952.27 27.20 561.40 67125.64 2874.36 |
| 356 588.60 209540.87 22.76 565.84 67691.48 2308.52 |
| 357 588.60 210129.47 18.28 570.32 68261.80 1738.20 |
| 358 588.60 210718.06 13.76 574.84 68836.64 1163.36 |
| 359 588.60 211306.66 9.21 579.39 69416.03 583.97 |
| 360 588.60 211895.26 4.62 583.97 70000.00 0.00 |
-------------------------------------------------------------------------
Notes:
Generate the table so that you would get valid output for a 30 year loan
or a 5 year loan.
Formatting in C++ is rather involved.
You want to make sure that the periods (in the numbers) line up.
Before you start printing, you should specify the number of
decimal places to be printed. You should also specify that
the numbers should be printed in fixed format. You only have
to do this once.
cout << setprecision(2) << fixed
To print a variable 'var', right justified, in 10 columns,
use the following.
cout << setw(10) << var;
setw is used to specify the number of columns
setprecision is used to specify the number of decimal places.
fixed is used to specify that the number is NOT to be printed in scientific notation.
To use the preceding formatting options, you will need the following
preprocessor command at the top of your program.
#include <iomanip>
Amortization schedule program on the Internet