Can someone please check if this program is correct.... i'm trying to write a PI approximation....but i can't get the output that i have to obtain....... suggestions?????
Code:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double pi=0, y=1;
int num, i;
char ch;
pi = 4 - 4/3 + 4/5 - 4/ 7 + 4/ 9 - 4/11 + 4/13 - 4/15;
pi = 0;
y = 1;
do
{
cout<<"How many terms do you want to use?\n";
cin>>num;
for (i = 1; i<=num; i++)
if (i%2 == 0)
pi = pi - 4/y;
else
pi = pi + 4/y;
cout<<pi,;
y = y + 2;
cout<<"Do you want another approximation? please enter Y or N\n";
cin>>ch;
}while (ch!= 'n' && ch!= 'N');
return 0;
}