When you borrow money to buy a house, a car , or for some other purpose, then you typically repay it by making periodic payments. Suppose that the loan amount is L, r is the interest rate per year, m is the number of payments in a year, and the loan is for t years. Suppose that i = ( r / m ) and r is in decimal. Then the periodic payment is:
you can also calculate the unpaid loan balance after making cretin payments. For example the unpaid balance after making k payments:
Where R is the periodic payment.( Note that if the payments are monthly, then m =12).
source : Malik, D. (2009). User-defined functions 1. In C programming: From problem analysis to program design (4th ed.). Boston, MA: Course Technology.
***************************************************************************************************************************************************************************************************************************************************
The code :
#include <iostream>
#include <cmath>
using namespace std;
void calculate_L(int L, int m, int t, int K, double R, double i)
{
double y;
int E = (m*t) - K;
double j = (1 - pow(1 + i, -E ));
y = R*(j / i);
cout << " The unpaid balance after " << K << " payments is: " << y << endl;
}
double calculate_R(int L, int m, int t, int k, double i)
{
double R;
int E = -m*t;
R = ((L*i) / (1 - pow(1 + i, E)));
cout<<"The periodic payments is: "<< R ;
return R;
}
void main()
{
int L, m, t, k;
double r, i, R;
cout << " Enter the loan amount ( L ): ";
cin >> L;
cout << endl;
cout << " Enter the interest rate / year ( r ): ";
cin >> r;
cout << endl;
cout << " number of payments / year (m): ";
cin >> m;
cout << endl;
cout << " Enter the loan period ( t ) in years: ";
cin >> t;
cout << endl;
cout << " Enter the number of finished payments ( k ): ";
cin >> k;
cout << endl;
i = r / m;
R = calculate_R(L, m, t, k, i);
calculate_L(L, m, t, k, R, i);
system("pause");
}
#include <iostream>
#include <cmath>
using namespace std;
void calculate_L(int L, int m, int t, int K, double R, double i)
{
double y;
int E = (m*t) - K;
double j = (1 - pow(1 + i, -E ));
y = R*(j / i);
cout << " The unpaid balance after " << K << " payments is: " << y << endl;
}
double calculate_R(int L, int m, int t, int k, double i)
{
double R;
int E = -m*t;
R = ((L*i) / (1 - pow(1 + i, E)));
cout<<"The periodic payments is: "<< R ;
return R;
}
void main()
{
int L, m, t, k;
double r, i, R;
cout << " Enter the loan amount ( L ): ";
cin >> L;
cout << endl;
cout << " Enter the interest rate / year ( r ): ";
cin >> r;
cout << endl;
cout << " number of payments / year (m): ";
cin >> m;
cout << endl;
cout << " Enter the loan period ( t ) in years: ";
cin >> t;
cout << endl;
cout << " Enter the number of finished payments ( k ): ";
cin >> k;
cout << endl;
i = r / m;
R = calculate_R(L, m, t, k, i);
calculate_L(L, m, t, k, R, i);
system("pause");
}



ليست هناك تعليقات:
إرسال تعليق