Skip to content

Instantly share code, notes, and snippets.

@mikestratton
Created February 22, 2017 19:54
Show Gist options
  • Save mikestratton/ae3635f86c0ac1304fc89c422c791268 to your computer and use it in GitHub Desktop.
Save mikestratton/ae3635f86c0ac1304fc89c422c791268 to your computer and use it in GitHub Desktop.
Mortgage Payment Calculator. This program determines the monthly payments on a mortgage given the loan amount, the yearly interest, and the number of years.
//*****************************************************************
// Mortgage Payment Calculator program
// This program determines the monthly payments on a mortgage given
// the loan amount, the yearly interest, and the number of years.
//*****************************************************************
#include // Access cout
#include // Access power function
#include // Access manipulators
using namespace std;
const float LOAN_AMOUNT = 500000.00; // Amount of the loan
const float YEARLY_INTEREST = 5.5; // Yearly interest rate
const int NUMBER_OF_YEARS = 30; // Number of years
int main()
{
float monthlyInterest; // Monthly interest rate
int numberOfPayments; // Total number of payments
float payment; // Monthly payment
// Calculate values
monthlyInterest = (YEARLY_INTEREST / 100) / 12;
numberOfPayments = NUMBER_OF_YEARS * 12;
payment = (LOAN_AMOUNT *
pow(monthlyInterest + 1, numberOfPayments)
* monthlyInterest)/( pow(monthlyInterest + 1,
numberOfPayments) – 1 );
// Output results
cout << fixed << setprecision(2) << “For a loan amount of ”
<< LOAN_AMOUNT << ” with an interest rate of “
<< YEARLY_INTEREST << ” and a “ << NUMBER_OF_YEARS
<< ” year mortgage, “ << endl;
cout << ” your monthly payments are $” << payment
<< “.” << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment