Problem Description
My pi is an irrational number, i.e. it cannot be written as a fraction.
It's approximate value of p is 3:141592653589793. Below are 5
dierent series which can be used to approximate p:
1. P= 4(1-(1/3)+(1/5)-(1/7)+(1/9)-...
2. P= sqrt(12(1- (1/4)+(1/9)-(1/16)+(1/25)-...))
3. P= sqrt(6 (1+ (1/4)+(1/9)+(1/16)+(1/25)+...))
4. P= sqrt(8 (1+ (1/9)+(1/25)+(1/49)+... ))
5. P= sqrt(24((1/4)+(1/16)+(1/36)+(1/64)+... ))
My project has many menus so i will post here my fuction that i have problem....
i think if this problem it fixed then i will write the other problems
so on this fuction
user must choice one of the series then give how many iterations
want's and the program will display the pi value...
My problem is that... i don't undersand what iterations means...and
how i can't calculate the value pi with???
i try wiki and google but i found differents answers, also my english it not good so
you understand that it's difficult to me to understand the problem.....
I have a code here, and i want to tell me your opinion about that..
errors,Algorithm errors , etc..........
here is my code::::
void menu10()
{
int i;
double pi = 0;
char s;
system("cls");
system("color 01c");
cout << " ------------------------------------" << endl;
cout << " | Choice 1. |" << endl;
cout << " |----------------------------------|" << endl;
cout << " | |" << endl;
cout << " | |" << endl;
cout << " |Approximate Pi using one function.|" << endl;
cout << " | |" << endl;
cout << " | |" << endl;
cout << " |----------------------------------|" << endl;
cout <<""<<endl;
cout <<" Series"<<endl;
cout <<" ------"<<endl;
cout <<" 1. P= 4(1-(1/3)+(1/5)-(1/7)+(1/9)-..."<<endl;
cout <<" 2. P= sqrt(12(1- (1/4)+(1/9)-(1/16)+(1/25)-...))"<<endl;
cout <<" 3. P= sqrt(6 (1+ (1/4)+(1/9)+(1/16)+(1/25)+...))"<<endl;
cout <<" 4. P= sqrt(8 (1+ (1/9)+(1/25)+(1/49)+... ))"<<endl;
cout <<" 5. P= sqrt(24((1/4)+(1/16)+(1/36)+(1/64)+... ))"<<endl;
cout <<endl;
cout <<" Which series do you want? (1-5) ";
cin >> s;
if ((!s=='1') || (!s=='2') || (!s=='3') || (!s=='4') || (!s=='5'))
{
cout<<"ERROR......."<<endl;
cout<<"Program will be terminated"<<endl;
cin>>s;
}
else
if (s=='1')
{
cout <<" On how many iterations? ";
cin >>i;
for (long int n = 1; n <= i; n++)
{
pi += (double)(-1,+n+1)/(2*n-1);
}
// Calculating pi
pi *= 4;
cout << " Estimated PI value (" << i << " iterations): is "<< pi;
cin>>pi;
}
else
if (s=='2')
{
cout <<" On how many iterations? ";
cin >>i;
for (long int n = 1; n <= i; n++)
{
pi += (12*(-1,+n+1)/(2*n-1));
n++;
}
pi =sqrt(pi);
cout << " Estimated PI value (" << i << " iterations): is "<< pi;
cin>>pi;
}
else
if (s=='3')
{
cout <<" On how many iterations? ";
cin >>i;
for (long int n = 1; n <= i; n++)
{
pi += (6*(+1,+n+1)/(2*n+1));
n++;
}
// Calculating pi
pi =sqrt(pi);
cout << " Estimated PI value (" << i << " iterations): is "<< pi;
cin>>pi;
}
else
if (s =='4')
{
cout <<" On how many iterations? ";
cin >>i;
for (long int n = 1; n <= i; n++)
{
pi += (8*(+1,+n+1+1)/(2*n+1+1));
n++;
}
// Calculating pi
pi =sqrt(pi);
cout << " Estimated PI value (" << i << " iterations): is "<< pi;
cin>>pi;
}
else
if (s=='5')
{
cout <<" On how many iterations? ";
cin >>i;
for (long int n = 1; n <= i; n++)
{
pi += (24*(+1,+n+1)/(2*n+1+1+1));
n++;
}
// Calculating pi
pi =sqrt(pi);
cout << " Estimated PI value (" << i << " iterations): is "<< pi;
cin>>pi;
}
}