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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
double calcFactorFuncOne (double calcFactorOne, double k, double i, double m, double t)
{
double ipp = i + 1.0;
calcFactorOne = (1.0 - pow(ipp, k - (m * t)));
return (calcFactorOne);
}
double calcFactorFuncTwo (double calcFactorTwo, double i, double m, double t)
{
double ipp = i + 1.0;
calcFactorTwo = (1.0 - pow(ipp, (-1.0 * m * t)));
return (calcFactorTwo);
}
//20
double functionOne (double calcFactorOne, double R, double L, double i, double r, double m, double t)
{
i = (r / m);
R = ((L * i) / calcFactorOne);
return (R);
}
double functionTwo (double calcFactorTwo, double LPrime, double R, double i, double r, double m, double t, double k)
{
i = (r / m); //30
LPrime = (R * (calcFactorTwo) / i);
return (LPrime);
}
int main()
{
double L; //loan amount
double r; //annual percentage rate
double m; //number of payments per year
double t; //how long the loan is for in years 40
double i;
double k; //number of payments made
double R; //periodic payment
double LPrime = 0.0; //unpaid balance after making k payments
int exit;
cout << "Please enter the loan amount." << endl;
cout << "$";
cin >> L;
cout << " " << endl; //50
cout << "Please enter the annual percentage rate." << endl;
cout << "%";
cin >> r;
cout << " " << endl;
cout << "Please enter the number of payments to be made per year." << endl;
cin >> m;
cout << " " << endl;
cout << "Please enter the number of years the loan is for." << endl;
cin >> t;
cout << " " << endl; //60
cout << "Please enter the number of payments that have been made." << endl;
cin >> k;
R = functionOne (calcFactorFuncOne, R, L, i, r, m, t);
LPrime = functionTwo (calcFactorFuncTwo, LPrime, R, i, r, m, t, k);
cout << " " << endl;
cout << "The periodic payment is $" << R << "." << endl;
cout << " " << endl;
cout << "The unpaid balance is $" << LPrime << "." << endl;
cout << " " << endl;
cout << "Type 'exit' to exit." << endl;
cin >> exit;
}
|