so here is what i've come up with...
it seems to me like it should execute correctly, but somewhere something is causing my output to be bogus large numbers; however, it will compile... does anyone see my error, i can't figure it out...
Code:
#include<stdio.h>
void pi(int n, double *pi_value, int *iterations); //declare function
int main (void)
{
int n; //number of terms
int iterations = 0; //number of actual loop iterations in pi
double pi_value = 0; //computed value of pi
printf("Please enter an odd integer n; ")'
printf("quit with a non-positive or even integer:\n");
/*-- Read n and display pi. Quit with a non-positive n. --*/
scanf("%d", &n);
while(n>0 && n%2)
{
pi(n, &pi_value, &iterations);
printf("%17d: %0.81f with %d iterations\n", n, pi_value, iterations);
scanf("%d", &n);
}
return(0);
}
void pi(int n, double *pi_value, int *iterations)
{
int i;
int ADD = 1 // 1 = true & 2 = false
for(i=0; i<n; i++)
{
switch(ADD)
{
case 1:
*pi_value += (4/((n*2)-1));
ADD = 2;
break;
case 2:
*pi_value -= (4/((n*2)-1));
ADD = 1;
{ break;
}
(*iterations)++;
}