#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
double calcFactorFuncOne (double calcFactorOne, double k, double i, double m, double t)
{
double ipp = i + 1.0;
calcFactorOne = (1.0 - pow(ipp, k - (m * t)));
return (calcFactorOne);
}
double calcFactorFuncTwo (double calcFactorTwo, double i, double m, double t)
{
double ipp = i + 1.0;
calcFactorTwo = (1.0 - pow(ipp, (-1.0 * m * t)));
return (calcFactorTwo);
}
//
double functionOne (double calcFactorOne, double R, double L, double i, double r, double m, double t)
{
i = (r / m);
R = ((L * i) / calcFactorOne);
return (R);
}
double functionTwo (double calcFactorTwo, double LPrime, double R, double i, double r, double m, double t, double k)
{
i = (r / m); //30
LPrime = (R * (calcFactorTwo) / i);
return (LPrime);
}
int main()
{
double L = 0.0; //loan amount
double r = 0.0; //annual percentage rate
double m = 0.0; //number of payments per year
double t = 0.0; //how long the loan is for in years 40
double i = 0.0; //
double k = 0.0; //number of payments made
double R = 0.0; //periodic payment
double LPrime = 0.0; //unpaid balance after making k payments
int end;
cout << "Please enter the loan amount." << endl;
cout << "$";
cin >> L;
cout << " " << endl; //50
cout << "Please enter the annual percentage rate." << endl;
cout << "%";
cin >> r;
cout << " " << endl;
cout << "Please enter the number of payments to be made per year." << endl;
cin >> m;
cout << " " << endl;
cout << "Please enter the number of years the loan is for." << endl;
cin >> t;
cout << " " << endl; //60
cout << "Please enter the number of payments that have been made." << endl;
cin >> k;
R = functionOne(calcFactorFuncOne(L, r, m, t, i), R, L, i, r, m, t);
LPrime = functionTwo (calcFactorFuncTwo(L, i, m, t), LPrime, R, i, r, m, t, k);
cout << " " << endl;
cout << "The periodic payment is $" << R << "." << endl;
cout << " " << endl;
cout << "The unpaid balance is $" << LPrime << "." << endl;
cout << " " << endl;
cout << "Type 'end' to exit." << endl;
cin >> end;
}
Mortgage Loan Calculator
Page 1 of 14 Replies - 1927 Views - Last Post: 12 October 2010 - 09:04 AM
#1
Mortgage Loan Calculator
Posted 12 October 2010 - 08:08 AM
So after countless hours of trying to double check if my functions are being called and passed correctly; I noticed that when I compile my program the unpaid balance and my payment are coming up with invalid numbers. I checked my math and asked around for help but no one could really answer what I didn't know already. Could someone give me some feedback on as to where I'm failing with this program?
Replies To: Mortgage Loan Calculator
#2
Re: Mortgage Loan Calculator
Posted 12 October 2010 - 08:22 AM
I would start by using meaningful names for you variables and functions.
What are you inputting?
What are your results?
What do you expect?
Jim
What are you inputting?
What are your results?
What do you expect?
Jim
#3
Re: Mortgage Loan Calculator
Posted 12 October 2010 - 08:25 AM
calcFactorFuncOne IGNORES the input value of the first parameter.
Some general points.
Single letter identifiers are meaningless. So have things like Principle, numMonths etc.
Single letter idents are fine for loops and array subscripts. But the more meaningful a variable is, the more readable the name should be.
Likewise, functionone, functiontwo really doesn't add a great deal.
There is also no reason to give your function parameters different names. r passed to calcFactorFuncOne() becomes k for example.
Some general points.
Single letter identifiers are meaningless. So have things like Principle, numMonths etc.
Single letter idents are fine for loops and array subscripts. But the more meaningful a variable is, the more readable the name should be.
Likewise, functionone, functiontwo really doesn't add a great deal.
There is also no reason to give your function parameters different names. r passed to calcFactorFuncOne() becomes k for example.
#4
Re: Mortgage Loan Calculator
Posted 12 October 2010 - 08:58 AM
jimblumberg, on 12 October 2010 - 07:22 AM, said:
I would start by using meaningful names for you variables and functions.
What are you inputting?
What are your results?
What do you expect?
Jim
What are you inputting?
What are your results?
What do you expect?
Jim
Thank you Jim! Well the purpose was to have the user input loan amount, interest rate, number of payments per year, number of years of the loan and finally how many payment have already been made then output the payment price and unpaid amount. I hate using variables like that myself but I think that's how the professor wanted it.
#5
Re: Mortgage Loan Calculator
Posted 12 October 2010 - 09:04 AM
I would still use meaningful names... You should not be penalized for writing good code.
And the answer to the questions are??
Jim
And the answer to the questions are??
Jim
Page 1 of 1

New Topic/Question
Reply



MultiQuote




|