This formula should be : payment = pow((amount_of_loan)*(interest_rate) * (1+interest_rate), (number_of_years)) / pow((1+interest_rate), (number_of_years)) - 1;
Then here is this one : int final_payment = pow((amount_of_loan)*(rate_of_interest) * (1+rate_of_interest), (number_of_years)) / (pow((1+rate_of_interest), (number_of_years)) - 1);
Anyway, can you let us know about your assignment sample output?
Change the definition of the function: void calculatePayment(double& selling_price, double& rate_of_interest, double& down_payment, double& amount_of_loan, double downpayment_percentage, int& number_of_years, double& payment)
Change your function call in main: calculatePayment(selling_price, rate_of_interest, down_payment, amount_of_loan, downpayment_percentage, number_of_years, payment);
What is the selling price? :
10000
What is the rate of interest?:
15
What is the number of years in loan?:
20
Output Test:
Selling Price: 10000
Rate of Interest: 15
Number of Years: 20
Amount of Loan: 8000
Down Payment: 2000
Monthly Payment: 120000
Purpose: Monthly House Cost Calculation
Yeah, I'd say your monthly payment algorithm is seriously whacked! ;)
And closed account's algorithm is even worse, with the corrected code:
What is the selling price? :
10000
What is the rate of interest?:
15
What is the number of years in loan?:
20
Output Test:
Selling Price: 10000
Rate of Interest: 15
Number of Years: 20
Amount of Loan: 8000
Down Payment: 2000
Monthly Payment: 3.83376e+101
Purpose: Monthly House Cost Calculation
Using the way to calculate loan payments here, http://www.wikihow.com/Calculate-Loan-Payments I did the loan calculation in intermediate steps instead of one huge indecipherable statement:
What is the selling price? :
10000
What is the rate of interest?:
15
What is the number of years in loan?:
20
Output Test:
Selling Price: 10000
Rate of Interest: 15
Number of Years: 20
Amount of Loan: 8000
Down Payment: 2000
Monthly Payment: 105.343
Purpose: Monthly House Cost Calculation
As you can see, intermediate steps makes it less error prone. They make understanding what the code does MUCH easier as well! :D
Easier to read means easier to maintain.
Using intermediate steps in a complex calculation makes it easier to track down errors. Printing out the results of each step would help pinpoint where the error occurs.