could you tell me whats wrong....

double denom = 3;

double pi;

double x = -1;

int i;

pi = 4*(1-((double)1/denom));

for (i=1 ; i<=30000 ; i++){

x = x*-1;

denom = (double)x*(denom+2);

pi = pi + denom;

System.out.println(i + " " + denom);

this code supposed to print denom at an alternating operation sequence in increasing value by 2.. but it only prints

5, -7 ,5 ,-3 , 5, -7 , 5,-3 over and over. helP!

Re: could you tell me whats wrong....

double denom = 3;

double pi;

double x = -1;

int i;

for (i=1 ; i<=30000 ; i++){

pi = 4*(1-((double)1/denom));

x = x*-1;

if (i % 1000 == 0){

System.out.println(i + " " + pi);

denom = x*((double)1/(denom+2));

pi = pi + denom;

}

}

}

}

narrowed it down to this but still its not working

Re: could you tell me whats wrong....

I believe the problem is that switching the sign of denom makes it so when you ADD two each time, you are not always adding to the absolute value of the number, as adding to a negative gets it closer to 0

Re: could you tell me whats wrong....

yeah nevermind i got it already thank you anyways.... :)