I need to write a program that asks the user for the desired accuracy that they wish to calculate pi to. I am stuck on how to use the newton-raphson technique and how to use the accuracy as .001 or .0001 etc.
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
usingnamespace std;
int main()
{
double acc;
int i;
double pi;
cout<<"This program will calculate the value of pi to the desired accuracy"<<endl
<<"Please input the desired accuracy. (i.e. .001, .0001 etc."<<endl;
cin>>acc;
system("cls");
for (i = 1; i<= 100000; i+2)
pi = 4*(1/i);
cout<<pi<<endl;
system("Pause");
return 0;
}
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
usingnamespace std;
int main()
{
double acc;
int i;
double pi;
double pie = 3.14159265359;
cout<<"This program will calculate the value of pi to the desired accuracy"<<endl
<<"Please input the desired accuracy. (i.e. .001, .0001 etc."<<endl;
cin>>acc;
system("cls");
do
{
for (i = 1; i<= 100000; i= i+2)
pi = 4*(1/i);
cout<<pi<<endl;
}
while(abs(pie - pi) > acc);
system("Pause");
return 0;
}