//Natalie Zarate CIS5 Chapter 3 P. 146 #17
/*******************************************************************************
*
* COMPUTE EARNED INTEREST
* _____________________________________________________________________________
* This program will accept as input the monthly interest rate, the loan amount,
* and the number of payments made toward the loan, then computes the monthly
* payment, how much of the loan was paid off and the amount of interest paid.
*
* Computation is based on the formula
*
* payment = ((rate * (1 + rate)^N) / ((1 + rate)^(N) - 1)) * L
*
* where rate is the monthly interest rate, N is the number of payments, and L
* is the original loan
* _____________________________________________________________________________
* INPUT
* rate : Monthly interest rate
* ogLoan : The initial loan amount
* numPay : Number of payments made on the loan
*
* OUTPUT
* monPay : Monthly payment
* loanPaid : Amount paid back
* intrestP : Amount paid in interest
*
* ****************************************************************************/
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
float rate; // INPUT - Monthly interest rate
float ogLoan; // INPUT - The initial loan amount
float numPay; // INPUT - Number of payments made on the loan
float monPay; // OUTPUT - Monthly payment
float loanPaid; // OUTPUT - Amount of the loan paid off
float interestP; // Output - Amount paid in interest
// Promt user for loan amount and display
cout << left << setw(25) << "Loan Amount:";
cin >> ogLoan;
cout << right << "$ " << setprecision(2) << fixed << ogLoan;
// Prompt user for monthly interest rate and display
cout << "\n" << left << setw(25) << "Monthly Interest Rate:";
cin >> rate;
cout << right << setw(9) << setprecision(0) << rate << "%" << endl;
// Prompt user for number of payments and display
cout << left << setw(25) << "Number of Payments:";
cin >> numPay;
cout << right << setw(10) << setprecision(0) << numPay << endl;
// Compute monthly payment
cout << setprecision(2) << fixed;
rate = 0.01;
monPay = 1 + rate;
monPay = rate * pow(monPay, numPay);
monPay = monPay / (pow((rate + 1) , numPay) - 1);
monPay = monPay * ogLoan;
// Display monthly payment
cout << left << setw(25) << "Monthly Payment:";
cout << right << "$" << setw(9) << monPay << endl;
// Compute amount paid back and display
loanPaid = monPay * numPay;
cout << left << setw(25) << "Amount Paid Back:";
cout << right << "$" << setw(9) << loanPaid << endl;
// Compute interest paid and display
interestP = loanPaid - ogLoan;
cout << left << setw(25) << "Interest Paid:";
cout << right << "$" << setw (9) << interestP << endl;
return 0;
}