ok i need a quick help here......
here it's my problem
It's approximate value of π is 3.141592653589793
Below are five different series which can be used to approximate π:
you can se the series here::
http://i44.tinypic.com/2ujtmxw.gif
ask which series he/she wants to use
and the precision (number of digits, up to 10). If after
10000 iterations the series doesn't find the value of π, it
should display an error message.
example:
Which series do you want?
2
How many digits of accuracy ?
5
It will display either an error message or the value of π and
the number of iterations necessary to obtain that value.
In order to round a real number to n decimal places.
My code is here:: but doesn't goes on if staytment.... i can't understand.. how i can round the numbers on if staytment??
int main()
{
char series;
int digits;
double pi1=0;
const double counter1=3.141592653589793;
long int counter=0;
cout << " Which series? (1-5): ";
cin>>series;
cout << " How many digits of accuracy? (<10): ";
cin>>digits;
if (series !='1' && series !='2' && series!='3' && series !='4' && series!='5')
{
cout <<" Error Input....."<<endl;
cout <<" Their are Only 5 series...(1,2,3,4,or5)"<<endl;
cout <<" The program will be terminated in 5 seconds..."<<endl;
Sleep(5000);
}
else
if (series=='1')
{
cout<<" Series 1"<<endl;
cout<<" --------"<<endl;
cout<<""<<endl;
for (long int n=1; n<=10000; n++)
{
pi1 += (4*pow(-1.0, n+1))/(2*n - 1);
if (pi1!=counter1)
{//if start
counter++;
}//if end
else
if(pi1!=counter1)
{
cout<<"Series "<<series<<" is approximate on "<<counter<<" iterations"<<" Series "<<series<<" is "<< fixed <<setprecision(digits) << pi1;
cin>>pi1;
}
else{
cout<<"This series dosn't approximeta on p value....change series"<<endl;
}