i got it now thanks
Last edited on
Change the 1 in the dividend to 1.0. Otherwise you're just performing an integer division.
You have two integer division (without digits after the decimal point).
Means: for all k > 0 the result of the formula on line 9 is 0. Change to:
answer += ( (1.0 / ( 2*k + 1)) ); // with .0 it is a floating point operation instead of integer