Quiz 4 Euler Number

Hello people, I was busy for a long time but here I am. This post is about my first quiz of the second partial of the semester. It was not too difficult but I got in trouble with some parts of the code but I finally did it. Well, the instructions for the quiz were:

Create a function called euler_calc with a single parameter precision. The value of precision is used to determine when to stop calculating. Your calculation will stop when the two consecutive values estimating e differ by less than precision (remember to use absolute value when calculating the difference between two values here).

I search information on Wikipedia about the Euler number to get the idea, and I found interesting information about it: The number e is an important mathematical constant that is the base of the natural logarithm. It is approximately equal to 2.71828,[1] and is the limit of (1 + 1/n)n as n approaches infinity, an expression that arises in the study of compound interest. It can also be calculated as the sum of the infinite series.

Thanks Euler for doing our life easier and harder at the same time.

Here the code of my program.

euleeeeeereulerrrrrrrrr

The new thing here was the SET PRECISION function that I used to call to the user for the number of decimals that he wants to use.

It has to look like that:

#include <iomanip>      // std::setprecision

int main () {
  double f =3.14159;
  std::cout << std::setprecision(5) << f << 'n';
  std::cout << std::setprecision(9) << f << 'n';
  std::cout << std::fixed;
  std::cout << std::setprecision(5) << f << 'n';
  std::cout << std::setprecision(9) << f << 'n';
  return 0;
}

**Don't forget to use the iomanip library to run it without problem.

And the program running:

euruning
dancing-banana
WORKS BABY!!. dancing-banana Regards: Eduardo Morales ;) Remember to check my codes on github, here the link: https://github.com/eduardomrlsg/TC101/blob/master/Quiz4%20EULER

CC BY-SA 4.0 Quiz 4 Euler Number by eduardomoralesg is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.