#include #include #include using namespace std; const int PAYMENTS_PER_YEAR = 12; int main() { float principal, rate; int years, payments; float monthlyInterestRate, monthlyPayment; // print instructions cout << "This program will compute the monthly payments for a mortgate" << endl << endl; // ask for parameters cout << "Enter the number of years => "; cin >> years; cout << "You will have the loan for " << years << " years." << endl; cout << endl; cout << "Enter the amount borrowed (as a decimal number) => "; cin >> principal; cout << fixed << setprecision(2); cout << "You borrowed $" << principal << endl; cout << endl; cout << "Enter the interest rate (as a percent) => "; cin >> rate; cout << "Your interest rate is " << rate << "%, or " << rate/100.0 << endl; cout << endl; // Compute mortage // the monthly rate is used twice in the computation so do it early monthlyInterestRate = rate/(100.0 * PAYMENTS_PER_YEAR); // the exponent in the mortgage formula is the number of payments. payments = PAYMENTS_PER_YEAR * years; // this is the mortgage formula // P r/n // payment = ------ // 1-(1+r/n)^(-nt) monthlyPayment = monthlyInterestRate * principal / (1 - pow((1 + monthlyInterestRate),-payments)); // print the results cout << "Your monthly payments will be $" << monthlyPayment << endl; return 0; }