Euler's number loop

Mar 30, 2016 at 5:11am
closed account (owCkSL3A)
I am trying to find Euler's Number to an accuracy inputted by the user in the form of (.001, .00001.....)

i believe my error is with the math and the start points but i cannot figure out where. Does anyone know and will point me to where i need to look at and change?

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
39
  #include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
using namespace std;




int main()
{
	double acc;
	double dif;
	double i=1;
	double x = 1;
	double e;
	double e2=1;

	cin >> acc;

	do
	{
		i *= x;
		x++;
		e = 1 + 1 / i;

		dif = abs(e - e2);
			
		cout << endl << e << endl;
	} while (dif > acc);

	
		
	cout << e;


	system("pause");
	return 0;
}
Last edited on Mar 30, 2016 at 5:13am
Mar 30, 2016 at 6:08am
Do not double-post. First thread: http://www.cplusplus.com/forum/beginner/187837/
Mar 30, 2016 at 6:14am
closed account (owCkSL3A)
I took my idea in a completely different direction changing basically everything in my program making the first post irrelevant which is why I did a second post.
Mar 30, 2016 at 6:22am
Yes, but multiple postings are ultimately a time waster for those who reply. Now you might get a whole lot of respondents to both posts, all saying the same thing. We would all much rather one Topic, never mind whether it goes off on a tangent or not.

Look at my reply to the other one, there is some advice on how to track down the problem yourself. Problem solving and debugging are good skills to have.
Topic archived. No new replies allowed.