Leibniz series with newton raphson loop

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.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 #include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
using namespace 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;
}
This is what i have without using the 'newton-raphson' technique, why isn't it working?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
using namespace 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;
}
Oh, how do i apply a series to the equation for pi?
Topic archived. No new replies allowed.