C++ - Mortgage Payment Calculation Program - CPP
C++ - Mortgage Payment Calculation Program - CPP
#include <cstdlib>
#include <iostream>
#include <cmath>
using namespace std;
class Mortgage
{
public:
Mortgage (float fAb, float fYI, int nYEARS)
: fAborrowed(fAb), fYint(fYI), nyears(nYEARS)
{}
float PMT ()
{ float fMint=(fYint/(12*100));
// A = D[i(1 + i)^n]/[(1 + i)^n - 1]
one_plus_i_to_n = pow( (1+fMint), (nyears*12) );
fPAmount = fAborrowed * (fMint * one_plus_i_to_n) /
(one_plus_i_to_n -1);
return (fPAmount);
}
private:
float fMint;
float fPAmount;
float fAborrowed;
float fYint;
float one_plus_i_to_n;
int nNM;
int nyears;
};
int main ()
{
float Principal =0;
float Yint=0;
int nY=0;
float Payment;
cout << "Enter Principal " << endl;
cin >> Principal;
cout << "Enter Yearly Interest Rate " << endl;
cin >> Yint;
cout << "Enter number of years " << endl;
cin >> nY;
Mortgage M (Principal, Yint, nY);
Payment=M.PMT();
cout << "Mortgage Payment --> " << M.PMT() << endl;
return 0;
}