-1

I have the following statements:

const double s=1529340.57;
double f=1-1/1200;
for(j=1;j<=384;j++){
    printf("Age %3d month %2d you have $%.2lf\n", (j+816) / 12, (j+816)%12, s*pow(f,j-1)-4000*((pow(f,j-1)-f)/(f-1)-1));
}

and I'm expecting to have the following results:

Age  68 month  1 you have $1526615.02
Age  68 month  2 you have $1523887.20
Age  68 month  3 you have $1521157.11

and so on.

But, I obtained the following output:

Age  68 month  1 you have $-1.#J
Age  68 month  2 you have $-1.#J
Age  68 month  3 you have $-1.#J

Do you know why? Thanks!

BGandul
  • 17
  • 5

1 Answers1

0

Try double f=1-1/1200.0;. As Jean-François Fabre already mentioned 1-1/1200 is not intepreted as double in your version of code. The 1200.0 forces the compiler to handle your formular as decimal.

mich1985
  • 61
  • 1