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
|
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
double firstfunction (double Ray, double Loan, double interest, double ments, double tym, double rate)
{
rate = rate / 100;
interest = (rate / ments );
Ray = (( Loan * interest )/ 1 - (pow(1 + interest, - (ments * tym))));
return Ray;
}
double secondfunction (double Lp, double Ray, double interest, double rate, double ments, double tym, double amnt)
{
rate = rate / 100;
interest = ( rate / ments );
Lp = Ray * ( 1 - pow( 1+ interest, -(ments * tym - amnt))) / interest;
return Lp;
}
int main ()
{
double rate;
double ments; //number of payments per year ments = 12
double tym; // length of years loan is taken out for
double amnt; // amount of payments made
double Loan; // Loan amount
double Lp = 0; // unpaid balance
double Ray = 0; // Periodic payment
cout << "Enter the loan amount: ";
cin >> Loan;
cout << endl;
cout << "Enter the interest rate per year as a percentage: ";
cin >> rate;
cout << endl;
cout << "Enter the number of payments per year: ";
cin >> ments;
cout << endl;
cout << "Enter the number of years for the loan: ";
cin >> tym;
cout << endl;
double interest = 0;
Ray = firstfunction (Loan, interest, ments, tym, rate, Ray);
cout << "The periodic payment is: " << Ray;
cout << endl;
cout << "Enter the number of payments made: ";
cin >> amnt;
cout << endl;
Lp = secondfunction (Lp, Ray, interest, rate, ments, tym, amnt);
cout << "The unpaid balance after " << amnt << " payment(s) is: "<< Lp;
cout << endl;
system ("pause");
return 0;
}
| |