Hi guys I need help with my code this is my homework "Write a C++ program that will calculate the value of e (Eulers number, e = 2.71828
) using a function you create named find_e. It shall have no arguments and return no values using the return statement. All transfer of information to and from the function must be in the form of global variables. The function find_e must be contained in a file separate file the file containing the main function . All output must be from the main program"
I made the program without global variables so you guys can see how it should look
/*#include <iostream>
#include <cmath>
using namespace std;
int main ()
{
double e;
double n;
double accuracy;
int euler = 2.7182818284590452353602874713527;
cout <<"insert the n value "<<endl;
cin>>n;
e=(1+1/n);
e=pow(e,n);
cout<<e<<endl;
accuracy=abs(euler-e);
cout<<"the accuracy is "<<accuracy<<endl;
system ("pause");
return 0;}
*/
and with global variables
this is my function.cpp
#include <iostream>
extern double n;
extern double e;
extern double accuracy;
double euler =2.7182818284590452353602874713527;
void f()
{
e=(1+1/n);
e=pow(e,n);
accuracy=abs(euler-e);
};
*/
and main.cpp
/*
#include <iostream>
#include <cmath>
using namespace std;
double n;
double e;
double accuracy;
int main ()
{
cout <<"insert the n value "<<endl;
cin>>n;
cout<<::e<<endl;
cout<<"the accuracy is "<<::accuracy<<endl;
system ("pause");
return 0;}
*/
I just get a 0 as answer D:
I made the program without global variables so you guys can see how it should look
/*#include <iostream>
#include <cmath>
using namespace std;
int main ()
{
double e;
double n;
double accuracy;
int euler = 2.7182818284590452353602874713527;
cout <<"insert the n value "<<endl;
cin>>n;
e=(1+1/n);
e=pow(e,n);
cout<<e<<endl;
accuracy=abs(euler-e);
cout<<"the accuracy is "<<accuracy<<endl;
system ("pause");
return 0;}
*/
and with global variables
this is my function.cpp
#include <iostream>
extern double n;
extern double e;
extern double accuracy;
double euler =2.7182818284590452353602874713527;
void f()
{
e=(1+1/n);
e=pow(e,n);
accuracy=abs(euler-e);
};
*/
and main.cpp
/*
#include <iostream>
#include <cmath>
using namespace std;
double n;
double e;
double accuracy;
int main ()
{
cout <<"insert the n value "<<endl;
cin>>n;
cout<<::e<<endl;
cout<<"the accuracy is "<<::accuracy<<endl;
system ("pause");
return 0;}
*/
I just get a 0 as answer D: