Oct 6, 2008 at 10:22pm UTC
I am working on a program with a formula that requires a negative exponent and I cannot figure out how to represent a negative exponent in the equation.
P = M(i/(1-(1+i)^-n))
I have tried a number of things, but I keep missing the mark.
doublePayment = doubleMortgage ( doubleMonthlyInterestRate / 1 - (pow(( 1 + doubleMonthlyInterestRate ) ^-doubleNumberOfPayments )));
I'm also wondering if I am using the wrong variable type...should I be using float?
Thanks,
Christy
Oct 7, 2008 at 12:04am UTC
O_o To represent a negative exponent. All you have to do is divide 1 over the positive exponent. Ex: 6^-2 = 1/(6^2).
So I guess you can change your code to this:
P = M(i/(1-(1/((1+i)^n))))
doublePayment = doubleMortgage ( doubleMonthlyInterestRate / 1 - (1/(pow(( 1 + doubleMonthlyInterestRate ) ^doubleNumberOfPayments ))));
Last edited on Oct 7, 2008 at 12:09am UTC
Oct 7, 2008 at 12:20am UTC
Well that's because in C++ the ^ is the bitwise xor operator...you will need to use the pow() in order to do it.