many compiling issues with pi approximation

I have a program written where I can approximate pi with an n value entered.The outputs need to look like either: (not computable due to negative):
This program approximates pi using an n-term series expansion.
Enter the value of n> -3
-3 is an invalid number of terms

or:(all positive numbers):
This program approximates pi using an n-term series expansion.
Enter the value of n> 6
pi[6] = 4[1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11] = 2.97604617604617560644


Here is the program I have so far. I am lost as to what to do to this to get it to work:

#include<iostream>
#include<cmath>

using namespace std;
void compute_pi(const int PRECISION)
{
double pi =4.0;
for(int =0; i< PRECISION ++i)
{
pi += (i%2 == 0 ? -4.0: 4.0)/(3.0+i*2);
}
return(pi);
}

int main()
{
double i;

cout<<"This program approximates pi using an n-term series expression."<<endl;
cout <<"Enter the value of n>" << endl;
cin >> i;

compute_pi();
cout <<"pi["<<i<<"] = 4["<<i<<"] = "<< pi << endl;
return 0;
}





Some insight would be greatly appreciated. Thank you for your time and knowledge.


Topic archived. No new replies allowed.