I have to implement a simple infinite sum which estimates the value of PI. The more iterations of the infinite sum, the more accurate the value of PI. Using the equation PI=4x(1-1/3+1/5-1/7+1/9-1/11+1/13-....)
.The details of the program are as follows:

1. The program must have a small menu for the purpose of user
interaction. The menu will contain the following choices:

1. Exit the program
2. Set how many digits past the decimal point are to be calculated
3. Calculate the value of Pi
(this part works for me)

2. I have to figure out how to determine when a digit is valid. (probably
by converting the floating point value of PI to a string and
checking for how many iterations the value of a digit is
unchanged.) Any valid algorithm to determine a valid digit is fine;


here is my code so far

I have to implement a simple infinite sum which estimates the value of PI. The more iterations of the infinite sum, the more accurate the value of PI. Using the equation PI=4x(1-1/3+1/5-1/7+1/9-1/11+1/13-....)
.The details of the program are as follows:

1. The program must have a small menu for the purpose of user
interaction. The menu will contain the following choices:

1. Exit the program
2. Set how many digits past the decimal point are to be calculated
3. Calculate the value of Pi
(this part works for me)

2. I have to figure out how to determine when a digit is valid. (probably
by converting the floating point value of PI to a string and
checking for how many iterations the value of a digit is
unchanged.) Any valid algorithm to determine a valid digit is fine;


here is my code so far

if anyone could help me it would really save me

if anyone could help me it would really save me

i am using codeblocks and the gcc compiler

#include <stdio.h>
#include <math.h>
#include <float.h>


//Define PI
#define PI 3.14159265

int main()
{
    //Variable declarations
    double a=DBL_MAX, b=DBL_MAX, c=DBL_MAX;

    //Menu control variable set to an initial value
    int inpUserChoice=0;

    //Main superloop structure
    while(inpUserChoice!=1)
    {


        if(b!=DBL_MAX)
            printf("\n# of digits = %.0lf", b);
        else
            printf("\n#of digits = UNDEFINED");

        //output menu choices
        printf("\n\n 1. Exit Program");
        printf("\n 2. Set how many digits past the decimal point are to be calculated");
        printf("\n 3. Calculate the value of Pi");


        //Prompt the user for input
        printf("\n\nEnter Selection: ");
        scanf("%d", &inpUserChoice);

        //Branch structure to handle selection
        if (inpUserChoice==3)

        {

            //Prompt the user for input
            printf("\n\nthe value of pi to %.0lf decimal spots is: %lf", b, PI);
            scanf("%lf", &a);
        }
        else if (inpUserChoice==2)
        {
            //Prompt the user for input
            printf("\n\nEnter the number of digits to be calculated: ");
            scanf("%lf", &b);
        }

        else if (inpUserChoice==1){
            printf("Exiting program...");
            return 0;}
        else
            printf("\n\nINVALID SELECTION %d is not an option in this program\n\n", inpUserChoice);    }

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.