/* testsel5.cpp CIS 150 6/2/2005 David Klick Demonstration of conditional (?:) operator. Calculates the maximum value three different ways. */ #include using std::cout; using std::cin; int main(void) { int x, y; int max1, max2, max3; // get two integers from user cout << "Enter two integers: "; cin >> x >> y; // first way // - use simple if/else to get max value if (x > y) { max1 = x; } else { max1 = y; } // second way // - assume x is max value, then check to see if y is bigger max2 = x; if (y > max2) { max2 = y; } // third way // - use conditional operator max3 = x>y ? x : y; cout << "The maximum value is " << max1 << '\n'; cout << "The maximum value is " << max2 << '\n'; cout << "The maximum value is " << max3 << '\n'; return 0; }