I’m doing some small program for a beginners programming course and in my program I have 2 variables which hold numbers. Anyway I need to find out which number is bigger and print the appropriate message according to it, for example I have:
int x = 5;
int y = 10;
I need to print:
“it is true that y is bigger than x”;
Now the thing is that I know I can use a simple if statement but I’m not allowed to use it, now it makes me wonder, is it even possible? If so, how can I do that? How can I check which number is bigger WITHOUT doing something like:
if (x > y)
answer = true;
…
Thanks in advance.
Well you can do:
The expression
x > yis just an expression of typeboolean. Whilebooleanexpressions are often used for conditions inifstatements, loops etc, they don’t have to be – simple assignment works fine too.It sounds like you want the reverse though:
Then you can use the value of
answerto build the string to display…