//Maxwell Brewer CS1A Chapter 3, P. 147, #17
//
/***************************************************************
*
* CALCULATE MONTHLY PAYMENTS
* _____________________________________________________________
*
* This program will prompt the user for for the loan amount,
* annual interest rate, and the number of payments.
* _____________________________________________
* INPUT
*
* Loan amount, annual interest rate, number of payments
*
* OUTPUT
*
* monthly payment, interest rate, total cost
*
***************************************************************/
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
using namespace std;
int main() {
// Initialization
double loanAmt;
double monthlyInt;
double monthlyPay;
double totalPay;
double intPaid;
double annualInt;
int numPay;
// Display input prompts
cout << "Enter the loan amount: \n";
cin >> loanAmt;
cout << "Enter the annual interest rate as percent: \n";
cin >> annualInt;
cout << "Enter number of payments: \n";
cin >> numPay;
monthlyInt = annualInt/(12*100);
monthlyPay = (monthlyInt * pow((1+monthlyInt),
numPay)) / ((pow((1+monthlyInt),
numPay) - 1)) * loanAmt;
totalPay = numPay * monthlyPay;
intPaid = totalPay - loanAmt;
// Output
cout << fixed << setprecision(2) << endl;
cout.width(10);
cout << "Loan Amount: $" << loanAmt << endl;
cout << "Monthly Interest Rate: " << monthlyInt << endl;
cout << "Number of Payments: " << numPay << endl;
cout << "Monthly Payment: $" << monthlyPay << endl;
cout << "Amount Paid Back: $" << totalPay << endl;
cout << "Interest Paid: $" << intPaid << endl;
return 0;
}