59.1k views
1 vote
Assume that a bool variable isQuadrilateral has been declared, and that an int variable, numberOfSides has been declared and initialized. Write a statement that assigns the value of isQuadrilateral to true if numberOfSides is exactly 4 and false otherwise.

Instructor Notes:
Hint: The result of evaluating a conditional expression is true/false, and can be assigned to bool variable, e.g.,
bool x = y == z;
Note == is the relational equality operator and = is the assignment operator. This statement will compare y and z to see if they are equal, which is either true or false. Then the true/false value will be assigned to Boolean variable x.

1 Answer

4 votes

Answer:

isQuadrilateral = (numberOfSides == 4);

Step-by-step explanation:

The explanation is given in the instructor notes!

User Arno Tenkink
by
8.3k points
Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.