Negative Exponents

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
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
Well that's because in C++ the ^ is the bitwise xor operator...you will need to use the pow() in order to do it.
Topic archived. No new replies allowed.