Created
February 22, 2017 19:54
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//***************************************************************** | |
// 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