Global variable and separate files

I am supposed to calculate Euler's number in a separate file to a given tolerance and return it using only global variables. After in cin a tolerance, it basically crashes. Do i have an infinite loop, or am i not sending any variables back?

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
40
41
  #include<iomanip>
#include<iostream>
#include<cmath>
#include<string>

using namespace std;

void find_e();
double tol = 0;
extern double e;
extern double diff;
extern double newe;
string ans = "yes";
int main()
{
	while(ans == "yes")
	{

	cout<<"This program will estimate the value of Euler's number to your desired tolerance"<<endl<<endl;
	cin>>tol;
	system("cls");

	if(tol > 0.0)
	{
		
			find_e();

			cout<<"The new value of e is "<<endl;
			cout<<"The actual value of e is "<<endl;
			cout<<"The difference is "<<endl;
	}

	else
	{
		cout<<"You can't have a negative tolerance"<<endl<<endl;
	}

	}
	system("pause");
return 0;
}


..and here is my separate file with the function to calculate "e".

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


extern double e = 0;
double euler = 2.718281828459045;
double newe = 0;
double diff = 0;
int n = 0;
extern double tol;

void find_e()

{

	do
		{

			e = 1+1/n;
			e = pow(e,n);
			diff = abs(newe - e);
			newe = e;

			n*=2;

		}
		while(diff>tol);




	return;
}
in my cout i also have <<e, <<euler, and <<diff. and i have extern double diff before my main
found it, i was dividing by 0.
Still getting odd answers for my couts though
Topic archived. No new replies allowed.