Exponents in formulas

Hello doing a project for school and little confused by my error.
this is my formula;
so I have all my values declared as doubles.
And then after declaring everything I put it into this formula


Monthly_payment = New_total *(((Monthly_interest * ((1+Monthly_interest)^(Num_Months_Loan))/((1+Monthly_interest)^Num_Months_Loan)-1));


so in it you can see that (1+montly_interest)^num_months_loan)

and in trying to raise 1+montly interest to num_months_loan
i get an error
"error: invalid operands of types ‘double’ and ‘double’ to binary ‘operator^’"


which I read is because you cant do the power to something like that and have to use pow(x,y)


but is there a way to do this without cmath and just using the formula like this?
Correct, the ^ operator is bitwise XOR in C++. Not what you want. ( http://xor.pw/ )

If the power is an integer, you can manually unfactor it, e.g. x^3 -> x * x * x

However, if the power is not an integer, just use the pow function. I don't really understand what you have against it... I mean you could do math and turn it into its equivalent log(n, base) format, but that's just as complicated, if not more complicated.

1+montly_interest)^num_months_loan becomes
pow(1+montly_interest, num_months_loan)
Last edited on
i figured not to use cmath because it was not shown or spoken of at any of our lectures, but I cant find any other way to do it. So I will go with pow.

Thank you for your help and have a good day.
Topic archived. No new replies allowed.