Help on c++ (how to round correctly the pi value)
Help on c++ (how to round correctly the pi value)
Hi, I've a couple of comments:
- digits variable isn't used by the series approximation. You get exactly the same value regardless of digits.
- In you final code you've used series 1; where as in the example usage you enter series 2.
- Pasting in your previous code for series 2, I get: 3.141592644041437 this is accurate to 7 significant digits.
- What is a 'long float', isn't that a 'double'. Either way gcc doesn't like it so I would avoid using them.
cout << PIWill only output to 5 significant digits, you therefore need something like
cout << setprecision(16); cout << PI
Login