# CS 19 Fall 2017

## Program One (Loan Payment Calculator)

### Filename

loan.cpp

### Program Description

Write a program ("loan.cpp") to calculate a loan payment. The program should output on a line by itself, your name and email. The second line line should list the due date, and include the assignment title and number. Then, prompt the user for the amount to be borrowed, the annual interest rate, the number of payments to be made each year, and the number of years the money is to be borrowed (in that order, one per line). Then output the amount of each payment, formatted to two decimal places and the total amount to be repaid, also formatted to two decimal places. Your program should input from STDIN and send output to STDOUT. Your program must have at least one function (in addition to main) to calculate and return the loan payment.

The equation for calculating the loan payment is:

where principal is the amount borrowed,
interest is the interest rate per payment,
and numPayments is the total number of payments that must be made.

For example, if $10,000 is borrowed at 12% annual interest rate,
to be repaid monthly for 4 years we would do the following calculations:

each payment = $263.34

total repaid = $12640.32

Note that you might get an answer of $12640.24 for the total amount to be paid if you multiply the raw value of each payment instead of the rounded value. This result is also acceptable.

### What to turn in

As usual, leave your .cpp file for this program ("loan.cpp") in your home directory on pengo.

### Suggestions

You may wish to use the following program as a model. Note that this example is not necessarily properly formatted. Don't forget to follow the Program Guidelines in your submission!

// Calculates volume of a cylinder #include <iostream> using namespace std; // constants (global const okay) const double PI = 3.14159265; // function prototypes double calcCylinderVolume(double, double); int main(){ double height, radius, volume; cout << endl << "Cylinder Voulume Calulator" << endl; cout << "What is the cylinder height? " << endl; cin >> height; cout << "What is the cylinder radius? "<< endl; cin >> radius; volume = calcCylinderVolume(height, radius); cout << endl << "A cylinder with height " << height; cout << " and radius " << radius; cout << " has a volume of " << volume << "." << endl; } double calcCylinderVolume(double h, double r){ return h * PI * r * r; }