g++ Compiler Problems?

According to the order of precedence, I would expect the expression:

20.0 -2.0/6.0 +3.0

To evaluate to be 22.6667.

However, I am using the g++ compiler and emacs. Here is my code...

#include <iostream>
using namespace std;

int main()
{
cout << 20.0 - 2.0/6.0 + 30.0 << endl;
return 0;
}

What exactly is the problem here? I get 49.6667.
Last edited on
You didn't type the first equation the same as the second.
Topic archived. No new replies allowed.