/* DemoPrecedence.cpp CIS 150 5/26/2005 David Klick This program demonstrates operator precedence. Multiplication, division, and modulus will be calculated before addition and subtraction. Parentheses can be used to override the normal precedence. */ #include using std::cout; using std::endl; int main(void) { double x = 3.0; double y = 5.0; double result1 = x + y / 2; double result2 = (x + y) / 2; double result3 = x + y * 2; double result4 = (x + y) * 2; cout << result1 << '\n'; cout << result2 << '\n'; cout << result3 << '\n'; cout << result4 << '\n'; return 0; } /* Sample output: 5.5 4 13 16 */