Sorry if this is old
Mar 14, 2014 at 4:42am UTC
I am trying to write a mortgage calculator for my C++ class and I can't figure out what is wrong. Cost is: $123,500 at 6.5% interest with 10% down.
This is what I have but when I run it I am getting error code.
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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
using namespace std;
// Declared constants
const int YEAR_FIFTEEN = 15; // First mortgage total 15 yrs
const int YEAR_THIRTY = 30; // Second mortgage total 30 yrs
const int YEAR_FORTY = 40; // Third mortgage total 40 yrs
const int MON_PER_YR = 12; // # of monthly payments per yr
int main ()
{
// Declared variables
int numOfPymts1;
int numOfPymts2;
int numOfPymts3;
float price;
float dwnPymt;
float interestRate;
float monthlyInterest;
float pymt1;
float pymt2;
float pymt3;
string lastName;
cout <<"Please enter the last name of the family purchasing the home; " ;
cin >> lastName;
cout << endl;
cout << "Please enter the home's price:" ;
cin >> price;
cout << endl;
cout << "Please enter the down payment percentage:" ;
cin >> dwnPymt;
cout << endl;
cout << "Please enter the interest rate as a percentage:" ;
cin >> interestRate;
dwnPymt = dwnPymt/100;
dwnPymt = price/dwnPymt;
interestRate = interestRate/100;
monthlyInterest = interestRate/MON_PER_YR;
numOfPymts1 = YEAR_FIFTEEN * MON_PER_YR;
numOfPymts2 = YEAR_THIRTY * MON_PER_YR;
numOfPymts3 = YEAR_FORTY * MON_PER_YR;
system ("pause" );
system ("cls" );
pymt1 =(monthlyInterest*(price-dwnPymt)) *pow ((1 + monthlyInterest), numOfPymts1)/(pow ((1 + monthlyInterest), numOfPymts1)-1);
pymt2 = (monthlyInterest*(price-dwnPymt))*pow ((1 + monthlyInterest), numOfPymts2)/(pow ((1 + monthlyInterest), numOfPymts2)-1);
pymt3 = (monthlyInterest*(price-dwnPymt))*pow ((1 + monthlyInterest), numOfPymts3)/(pow ((1 + monthlyInterest), numOfPymts3)-1);
cout << pymt1 << endl;
cout << pymt2 << endl;
cout << pymt3 << endl;
return 0;
}
Thank you in advance for any help you can give
Mar 14, 2014 at 4:48am UTC
What is the error?
Mar 14, 2014 at 12:37pm UTC
I think you want to multiply the price by the down payment percentage instead of dividing. Otherwise the result is greater than the price entered.
1 2 3 4 5 6 7
cout << "Please enter the down payment percentage:" ;
cin >> dwnPymt; //sample entry 10
cout << endl;
//
dwnPymt = dwnPymt/100; // = .10
dwnPymt = price/dwnPymt; // 123500/.10 = 1,235,000
Instead - multipy
dwnPymt = price*dwnPymt; //123500*.10 = 12,350
Topic archived. No new replies allowed.