--Originally published at my programming blog
So what we needed to do was a function that had just one parameter and to estimate the value of e.
I got help from this page and this video tutorial.
What I did was:
- I did first a float function where I calculated the factorial.
- Then In the second function my para meter was precision which is the number of decimal points I want in my result.
- Inside the function I only did a for loop where the condition was that while the int i was smaller or equal to precision this would happen : e will be equal to e plus 1/factorial of i.
- Then the function will cout (BUT IT WILL NOT PRINT ANYTHING) first it says fixed, which I used to start counting the precision form the decimal point, and the I used the function setprecision from the library “iomanip”. and at the end my function will return the value of e.
- Finally in my int main I just ask the user for the precision and then I call my functions with parameter that my user gave me.
My code in Github: https://gist.github.com/mariasantoyodl/2cb288d17ecc951b8349e226d651a36a