1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
double payment(double, double, double);
int main ()
{
// need a loop here!
double total, principle, interest, years;
cout << "Enter loan amount: ";
cin >> principle;
cout << "Enter interest rate: ";
cin >> interest;
cout << "Enter number of years to pay back loan: ";
cin >> years;
payment(principle, interest, years);
total = payment(principle, interest, years);
cout << "The monthly payment fon a " << years << " year $" << principle <<
" loan with an annual interest rate of " << interest << " is $" << total;
return 0;
}
double payment(double principle, double interest, double years)
{
double amount, A, P, r, n;
A = amount;
P = principle;
r = interest;
n = years;
A = P * pow(1+r, n) / pow(1+r, n)-1;
return amount;
}
|