#include <iostream>
#include <cmath>
using namespace std;
int main()
{
// define a constant conversion factor
const int MONTHS_IN_YEAR = 12;
//declare variables to hold the data
float loanAmount, annualInterestRate;
int loanPeriod;
double monthlyPayment, totalPayment;
double monthlyInterestRate;
int numberOfPayments;
cout << " -- LOAN CALCULATOR -- " << endl;
cout << "This program computes the monthly and total " << endl;
cout << "payments for a give loan amount, annual " << endl;
cout << "interest rate, and loan period. " << endl << endl;
cout << "Loan Amount : ";
cin >> loanAmount;
cout << "Annual interest Rate e.g. 9.5 : ";
cin >> annualInterestRate;
cout << "Loan Period # of years : ";
cin >> loanPeriod;
monthlyInterestRate = annualInterestRate / 100 / MONTHS_IN_YEAR;
numberOfPayments = loanPeriod * MONTHS_IN_YEAR;
monthlyPayment = (loanAmount * monthlyInterestRate) /
( 1 - pow(1 / (1 + monthlyInterestRate), numberOfPayments) );
totalPayment = monthlyPayment * numberOfPayments;
cout << "For " << endl
<< "Loan Amount: " << loanAmount << endl
<< "Annual Interest Rate: " << annualInterestRate << "%" << endl
<< "Loan Period (years): " << loanPeriod << endl
<< endl
<< "Monthly Payment : " << monthlyPayment << endl
<< " Total Payment : " << totalPayment << endl;
system("PAUSE");
return 0;
}