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
|
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
void ReadLoanInfo(int &Prin, int &Yea, int &PPY, float &Ra);
float MonthlyPayment (int Prin, int Yea, int PPY, float Ra);
void ShowTable (int Prin, int Yea, int PPY, float Ra, float MP);
void main()
{
int Principle=0, Years=0, PaymentsPerYear=0;
float Rate=0, PerMonth;
char Continue;
do{
ReadLoanInfo(Principle, Years, PaymentsPerYear, Rate);
PerMonth=MonthlyPayment(Principle, Years, PaymentsPerYear, Rate);
ShowTable(Principle, Years, PaymentsPerYear, Rate, PerMonth);
cout<<"To continue enter Y:";
cin>>Continue;}
while(Continue=='y'||Continue=='Y');
}
void ReadLoanInfo(int &Prin, int &Yea, int &PPY, float &Ra)
{
cout<<"Please enter the Principle: ";
cin>>Prin;
cout<<"Please enter the Annual Intrest Rate: ";
cin>>Ra;
cout<<"Please enter the number of Years: ";
cin>>Yea;
cout<<"Please enter the payments per year: ";
cin>>PPY;
}
float MonthlyPayment (int Prin, int Yea, int PPY, float Ra)
{
float IR, Bottom, Base, MP;
int Term;
IR=Ra/12.0;
Term=Yea*PPY;
Base=IR+1;
Bottom=(1-pow(Base, -Term));
MP=Prin*(IR/Bottom);
return MP;
}
void ShowTable (int Prin, int Yea, int PPY, float Ra, float MP)
{
int NoP=Yea*PPY;
cout<<"Principle---------->$"<<Prin<<endl;
cout<<"Interest Rate------>"<<Ra*100<<"%"<<endl;
cout<<"No. of Years------->"<<Yea<<endl;
cout<<"Payments Per Year-->"<<PPY<<endl;
cout<<"No. of Payments---->"<<NoP<<endl;
cout<<"Monthly Payment---->$"<<setprecision(2)<<MP<<endl;
}
|