C++ arithmetic if operator

Change

cout << test;

to

cout << test();

Otherwise you're not calling the function.

Also, the following:

return (x < y) ? true : false;

does the opposite of what you say you're trying to do ("return false if x < y").

The correct way is:

return (x < y) ? false : true;

Note that in this case the ternary operator is unnecessary, since you can simply do:

return !(x < y);

You state:

It suppose to return false if x < y

And you're trying to learn about the arithmetic if (ternary) operator, so ignore all the advice to eliminate it.

The first part after the ? is what will be returned if the expression is true, and the second part after the : is what will be returned if it is not true. Thus you have your return values reversed, and it should be:

return (x < y) ? false : true;

Tags:

C++