Im trying to show pi. I know how to set precision and all that, but I cant seem to get it! I did this:
Isnt this what I supposed to do? I think there's something to do with M_PI, but I type that in and its still underlined in red in my compiler. What mistake am I making?
EDIT: DO I have to type in all the digits of pi and then define it? just wondering
Last edited on
I think M_PI may be non-standard, depending on which compiler is used.
You could do this:
using namespace std;
const double PI = 4.0 * atan(1.0);
cout << "PI = " << setprecision(16) << PI << endl;
Line 9 uses the fact that the angle whose tangent equals 1, is PI/4 radians or 45 degrees. So calculate it once at the start of the program and from then on use the stored value.
Ok thank you.
Topic archived. No new replies allowed.