Need parentheses around the conditional expression. : tenary operator « Operators statements « C++ Tutorial






#include <iostream>
using namespace std;
int main(){
   int x, y;

   cout << "Enter two integers: ";
   cin >> x >> y;
   cout << x << ( x == y ? " is" : " is not" ) 
        << " equal to " << y << endl;

   return 0;
}








3.7.tenary operator
3.7.1.Use the ? operator to prevent a division by zero
3.7.2.Using the conditional operator to select output
3.7.3.A Demonstration of the Conditional Operator
3.7.4.Need parentheses around the conditional expression.