60.9k views
3 votes
Assume the int variables width and height have been defined. Write a statement that uses a relational expression to determine whether the variables are equal, and then stores the result of the expression in a bool variable named isSquare.

User MarkJ
by
3.5k points

1 Answer

5 votes

Answer:

bool isSquare = (width == height) ? true : false;

Step-by-step explanation:

The code above has been written using C++ language.

Assumptions and notes:

i. The width and height variables have been defined.

ii. The conditional operator ? : is used

The format of the conditional operator ? : is as follows;

(expression) ? xxx : yyy

Where;

==> expression is the condition to test. In this case whether width and height are equal. i.e width == height

==> xxx is the returned value or function if the expression is true. In our case, the value is the boolean true.

==> yyy is the returned value or function if the expression is false. In our case, the value is the boolean false.

And finally;

The returned value is assigned to a bool variable called isSquare

Putting all these together gives;

bool isSquare = (width == height) ? true : false;

User Steelight
by
3.9k points