hi.. ok here is my problem

i want to make a fuction that ask from the user 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 p, it
should display an error message.

It will display either an error message or the value of p and
the number of iterations necessary to obtain that value.
In order to round a real number to n decimal places.

here is my code, i post my code only for first series so if you have any ideas please help me:
Pi == 3.141592653589793
Example:
Which series do you want?
2
How many digits of accuracy ?
5
The Series 2 is approximate on 1000 iterations.. pi = 3.14159

or

The Series 2 is not approximate, try another series...

double pi=0,seriesValue=0;
const double counter=3.141592653589793;
if (series='2')
{
cout<<" Series 2"<<endl;
cout<<" ----------"<<endl;
cout<<""<<endl;
cout <<"How many digits of accuracy?;
cin>>digits;
for (long int n = 1; n <= 10000; n++)     //for loop for SERIES 2
     {//for loop start
     serieValue+= pow(-1.0, n+1)/pow(n,2.0);  // Calculating pi 
     pi=sqrt(12*serieValue);

     if  (pi1==counter)
    {   //if start for coutner
 cout<<"The Series 2 is approximate on "<<n<<" iterations pi of series 2 == "<<fixed<<setprecision(digits)<<pi1<<endl;
  } //if end  for coutner 
else 
cout<<"Error"<<endl;
} // for loop end
} //if end for series 2

Syntax errors notwithstanding, what problems are you having? What happens when you compile and run the code?

So you have to estimate/calculate pi am I right?
Could you please post the whole algorithm (+an example of the series)

ok here is an example of series 2

P= sqrt(12*(1- (1/4)+(1/9)-(1/16)+(1/25)-...))
^
||
if you want to present this: (giving of course the iterations by the user).. the code is here.......

for (long int n = 1; n <= i; n++)     //for loop for SERIES 2
     {//for loop start
     serieValue+= pow(-1.0, n+1)/pow(n,2.0);        // Calculating pi of SERIES 2
     } // for loop end
     pi=sqrt(12*serieValue);

so if the user gives 1000 the program print 3.14159 thats correct...

now i want a for loop to find automaticall step by step 10000 iterations and stop if find the correct value of pi... (pi==3:141592653589793) also user give a number to round this value (1-10) this is not a problem my problem is how to find step buy step all the numbers

If you automatically want to do 10000 iterations then you should simply change your for-loop to this:

for (long int n = 1; n <= [B]10000[/B]; n++)     //for loop for SERIES 2
     {//for loop start
     serieValue+= pow(-1.0, n+1)/pow(n,2.0);        // Calculating pi of SERIES 2
     } // for loop end
     pi=sqrt(12*serieValue);

By the way: are you using any high precision float/big number library?

>my problem is how to find step buy step all the numbers
If you mean finding all the numbers of pi, then you didn't pay enough attention in the lessons of maths: pi is an irrational number, which means you can't calculate all of it's digits because there are just infinite of them :)

>my problem is how to find step buy step all the numbers
If you mean finding all the numbers of pi, then you didn't pay enough attention in the lessons of maths: pi is an irrational number, which means you can't calculate all of it's digits because there are just infinite of them :)

I have not said that I want to find result of 'inexperienced numbers… but the first 10000.......

1 iterations = 4****
2 iterations =2.66***

10000 iterations = 3.14***

the i have the numbers but i want the iterations....

1. It looks like a black cat in the dark room (from the user interface point of view). What's series #1, #2 etc?
2. You NEVER get pi1==counter : you forgot that doubles are real number approximations.

the i have the numbers but i want the iterations....

:?:

1. It looks like a black cat in the dark room (from the user interface point of view). What's series #1, #2 etc?
2. You NEVER get pi1==counter : you forgot that doubles are real number approximations.

i have add the question of the problem 5 time,

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.

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

2. You NEVER get pi1==counter : you forgot that doubles are real number approximations.

also on which line i set that pi1 and counter is equal??? :?
i set the counter for the iterations not for the pi1 value...

Why are you just ignoring all the questions we ask you?
ArkM asked: What's series #1, #2 ... ?

Why are you just ignoring all the questions we ask you?
ArkM asked: What's series #1, #2 ... ?

here::::

http://i44.tinypic.com/2ujtmxw.gif

for (long int n = 1; n <= i; n++)          //for loop for PI SERIES 1 
	 {          // loop start
	  pi1 += (4*pow(-1.0, n+1))/(2*n - 1);    // Calculating pi  of first series  with for loop value of p is pi1
	 }         // loop end

for (long int n= 1; n <= i; n++)          //for loop for PI SERIES 2
     {        //loop start
serieValue1+= pow(-1.0, n+1)/pow(n,2.0);     // calculationg pi of second series with for loop  value of p is pi2
     }        // loop end
pi2=sqrt(12*serieValue1);

for (long int n = 1; n <= i; n++)        //for loop for PI SERIES 3
     {       // loop start
serieValue2+= pow(+1.0, n+1)/pow(n,2.0);     // Calculating pi of third series with for loop  value of p is pi3
     }       // loop end
pi3=sqrt(6*serieValue2);

for (long int j=1,n=1; n,j <= i; j++,n++) //for loop for PI SERIES 4                        
     { // loop start
if (j>=2)     //if staytment to check the j counter
n++;           // n=n+1 if the j>=2
serieValue3+= pow(+1.0, n-1)/pow(n,2.0);   // Calculating pi of the 4trd series  with for loop value of p is pi4
     }// loop end 
pi4=sqrt(8*serieValue3);
 
for (long int n = 1; n <= i; n++)         //for loop for PI SERIES 5                     
    {//loop start 
serieValue4+= pow(+1.0, n+1)/pow(n*2,2.0);  //Calculating pi five series with for loop  value of p is pi5
    }// loop end
pi5=sqrt(24*serieValue4);

this is my code for each series if the user add the iterations

if you don't know what the program ask and you don't know the answer then don't post, it's waste of time for someone that has a problem...........

you didn't help me!!!!!!!!!!
Thanks any way!!!!!!!!

if you don't know what the program ask and you don't know the answer then don't post, it's waste of time for someone that has a problem...........

you didn't help me!!!!!!!!!!

How can we help you if you don't give us a thorough description of your problem?

How can we help you if you don't give us a thorough description of your problem?

Are you serious ??? I have post my whole project 10 times...... what else i can do??

i have all my code on CPP with comment's but i don't know why the third part work... if you are interesting tell me an email private to send you the whole cpp with pdf of the project.........

for (long int j=1,n=1; n,j <= i; j++,n++) //for loop for PI SERIES 4                        
     { // loop start
if (j>=2)     //if staytment to check the j counter
n++;           // n=n+1 if the j>=2
serieValue3+= pow(+1.0, n-1)/pow(n,2.0);   // Calculating pi of the 4trd series  with for loop value of p is pi4
     }// loop end 
pi4=sqrt(8*serieValue3);

Is this the Equation You are having trouble with?
If yes , there are 2 reasons for that.
First syntax.

for (long int j=1,n=1; n,j <= i; j++,n++)

n,j<=i;
Would be n==0,j<=i;
I donot know if that is what you want .
Secondly If you see the power series. its
Denominator is progressing as in the square of odd numbers
So i think this should be

serieValue3+= pow(+1.0, n-1)/pow((2*n-1),2.0)

Odd numbers can be got in that way :)

for (long int j=1,n=1; n,j <= i; j++,n++) //for loop for PI SERIES 4                        
     { // loop start
if (j>=2)     //if staytment to check the j counter
n++;           // n=n+1 if the j>=2
serieValue3+= pow(+1.0, n-1)/pow(n,2.0);   // Calculating pi of the 4trd series  with for loop value of p is pi4
     }// loop end 
pi4=sqrt(8*serieValue3);

Is this the Equation You are having trouble with?
If yes , there are 2 reasons for that.
First syntax.

for (long int j=1,n=1; n,j <= i; j++,n++)

n,j<=i;
Would be n==0,j<=i;
I donot know if that is what you want .
Secondly If you see the power series. its
Denominator is progressing as in the square of odd numbers
So i think this should be

serieValue3+= pow(+1.0, n-1)/pow((2*n-1),2.0)

Odd numbers can be got in that way :)

Thanks for your posting....

The algorithm of all the series it's working perfect... i try it and works, ( you can't try it if you want )

my problem is here:::



The function 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 PI, it
should display an error message.


It will display either an error message or the value of PI and
the number of iterations necessary to obtain that value.
In order to round a real number to n decimal places, you
can use the following algorithm 78375 divided by 10 to the power of 3 = 78:375

any ideas???

>>In order to round a real number to n decimal places, you
>>can use the following algorithm 78375 divided by 10 to the power of 3 = 78:375

I am a little confused with the algorithm that has been mentioned above. Do you have anymore information about that algorithm?

>>In order to round a real number to n decimal places, you
>>can use the following algorithm 78375 divided by 10 to the power of 3 = 78:375

I am a little confused with the algorithm that has been mentioned above. Do you have anymore information about that algorithm?

open you calculation and make this equation....

78375 / 10 ^3 == (the answer is 78.375)

on c++ you can present it with that

double value=78375,total;
total=value/pow(10.0,3);

also
78375 / 10 ^4 == (the answer is 7.8375)

double value=78375,total;
total=value/pow(10.0,4);

Though I understood the above code. I dont think that we would get a real number as output for any of the series.

Although, If we get a real number from the series and if the user types 5,

DO we divide the number by pow(10,5)?

If that is the case.

You can run the function until Count reaches 10000 or until pi<=pow(10.0,n+!)//where n is the number of decimal places.

After pi is greater than pow(10,n+!) then that value can be divided by pow(10,n) and would lead to the answer.

Though I understood the above code. I dont think that we would get a real number as output for any of the series.

Although, If we get a real number from the series and if the user types 5,

DO we divide the number by pow(10,5)?

If that is the case.

You can run the function until Count reaches 10000 or until pi<=pow(10.0,n+!)//where n is the number of decimal places.

After pi is greater than pow(10,n+!) then that value can be divided by pow(10,n) and would lead to the answer.

something like that???

for (long int n = 1; n <= 10000; n++)            //for loop for SERIES 1
	 { //for loop start
		
		
			pi += (4*pow(-1.0, n+1))/(2*n - 1);               // Calculating pi of SERIES 1 
            while (pi < =pow(10.0,n+!))
{           
 counter++;
		}
		else
			break;
        } //for loop end

pi=pi/pow(10.0,digits);
int n=1;
while(n<=10000||pi2<=pow(10.0,digits)          //for loop for PI SERIES 2
     {        //loop start
serieValue1+= pow(-1.0, n+1)/pow(n,2.0);     // calculationg pi of second series with for loop  value of p is pi2

pi2=sqrt(12*serieValue1);
}
//Something Like the Above COde.
int n=1;
while(n<=10000||pi2<=pow(10.0,digits)          //for loop for PI SERIES 2
     {        //loop start
serieValue1+= pow(-1.0, n+1)/pow(n,2.0);     // calculationg pi of second series with for loop  value of p is pi2

pi2=sqrt(12*serieValue1);
}
//Something Like the Above COde.

Thanks my friend.... I try this::: ( please if you can check it and tell me if it's correct) Thank's

void menu4() //menu4() - Find the number of iterations to approximate Pi.
{
int counter=0,flag=0,digits;
char series;

long double pi1=0,total=0;
long double result=0,result1=0;
long double pi12=0,pi13=0,pi=0,serieValue=0;
long double ValuePi1=31;
long double ValuePi2=314;
long double ValuePi3=3141;
long double ValuePi4=31415;
long double ValuePi5=314159;
long double ValuePi6=3141592;
long double ValuePi7=31415926;
long double ValuePi8=314159265;
long double ValuePi9=3141592653;
long double ValuePi10=31415926535;
if (series=='2') 
{ // end of if SERIES 1 

cout << " How many digits of accuracy? (<10): ";
cin>>digits;  // ask the number of digits 

switch (digits)
{ //star of switch 
case 1:  result = ValuePi1/pow(10.0,digits);break;
case 2:  result = ValuePi2/pow(10.0,digits);break;
case 3:  result = ValuePi3/pow(10.0,digits);break;
case 4:  result = ValuePi4/pow(10.0,digits);break;
case 5:  result = ValuePi5/pow(10.0,digits);break;
case 6:  result = ValuePi6/pow(10.0,digits);break;
case 7:  result = ValuePi7/pow(10.0,digits);break;
case 8:  result = ValuePi8/pow(10.0,digits);break;
case 9:  result = ValuePi9/pow(10.0,digits);break;
case 10: result = ValuePi10/pow(10.0,digits);break;
} //end of switch 


cout<<endl;
cout<<"           ________        "<<endl;
cout<<"          |Series 1|       "<<endl;
cout<<" --------------------------"<<endl;
cout<<" Pi Aproximation is: "<<result<<" with "<<digits<<" digits accuracy"<<endl;
cout<<" --------------------------"<<endl;

for (int long n=1; n<=10000 && flag!=1; n++) 
{//star for loop
	
	   serieValue+= pow(-1.0, n+1)/pow(n,2.0); 
	   pi=sqrt(12*serieValue);
       pi12=ceil((pi*pow( 10.0,digits ) )- 0.49  ) / pow( 10.0,digits );;
	   
	   if (pi12==result)
	 {
	    flag=1;
	 }	  
	 else
		 counter++;
}//loop end
        if (flag==1)
	 { 
	   cout<<" Series "<<series<<" is approximate on "<<counter<<" iterations"<<" Series "<<series<<" is "<<pi12<<endl;
	   cin>>pi;
	 } // if end 
	 else 
		 cout<<"A: "<<pi<<endl;
     cout<<" This series doesn't approximate on Value PI...."<<endl;
	 cin.get();
}//if series =2
}//void()

I really dont know if it is correct or not. I hope that you get the correct output which is required thats all .

Is the output correct?

I really dont know if it is correct or not. I hope that you get the correct output which is required thats all .

Is the output correct?

97% it's correct, I'm working for the other 3 thank you very much......

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.