pow(x,y) is giving me varied results

Hi all,

I am trying to compute the monthly payout received from an invested annuity. I have determined that the finance mathematical formula is:

pmt = pv / [(1-(1+r)^(-n))/r]

I am using cin to receive the current values for pv,r, and n:

present value (pv) = 987000
rate (r) = 7
and number of years (n) = 30

when using a scientific calculator and plugging in the values to the best of my knowledge, I get the following results:

987000/((1-(1+0.58*100)^(-360))/0.58*100) = 5724.60

However when incorporating this into my c++ program and attempt to use:

double pmt,r,pv;
int n;
..
//process calculations 2
month_r = (r/12);
month_n = (n*12);
pmt = pv / ((1-(pow((1+((r/12)/100)),(-(n*12)))))/((r/12)/100));
..

I get the following (6566.54):

-----------------------------------------
Monthly payout received from the annuity.
-----------------------------------------
| Present Value : 987000.00|
| Rate (APR) : 7.00|
| Number of Years : 30|
| Monthly Payout Amount : 6566.54|
-----------------------------------------

Can anyone turn my head into the right direction as to why this is happening? I believe that my code is correct, but maybe missing something regarding datatypes or logical operation of the formula for this new language I'm diving into..

Thanks for any assistance in advance!

Geoff-

Post a main function that shows "exactly" what you are compiling and executing. Post a function that we can copy and paste into a new project, compile, and run for ourselves.
Topic archived. No new replies allowed.