# Thread: monthly payment from math to C++

1. ## monthly payment from math to C++

so my problem is that i really don't know how to convert the formula from this question into C++

the monthly payment on a loan may be calculated by the formula

payment = (Rate * (1+Rate)^N ) * Loan / ((1+Rate)^N - 1)

rate is the monthly interest rate which is the annual interest rate divided by 12
12% annula interest rate would be 1 percent monthly interest. N is the number of payments
Loan is amount of loan
write a program that asks for there values and displays a report similiar to:

Loan amount: \$ 10000.00
Monthly Interest Rate: 1%
Number of Payments: 36
Monthly Payment: \$ 332.14
Amount Paid Back: \$ 11957.15
Interest Paid: \$ 1957.15

2. It would be exactly like that except that there is no ^ operator in C++. You can use the function pow(). You need to #include <math.h>

3. so what hurts me here, is that i did it with power function.
and it's not working at all.

4. that's what i have

Payment = (Monthly_Interest_Rate * pow(1 + Monthly_Interest_Rate, Number_Of_Payments)) * Loan /( pow(1+Monthly_Interest_Rate, Number_Of_Payments) - 1) ;

5. is this what you're looking for?

I used the following formula in my program and with my code, it shows a monthly payment of 332.14 given the 10000.00 amount like your sample output wants.

Code:
`payment_amt = (loan_amt * monthy_interest_rate) / (1 - pow(1+monthy_interest_rate,-loan_term_months));`

Originally Posted by C_ntua
You need to #include <math.h>
Actually, use the #include <cmath> preprocessor directive. math.h is the old style math header for C++.