Ask Question
1 October, 19:48

How can the compound conditional expression ((average > 79 && average < = 89)) be written to eliminate the logical operator - without changing the logic?

+2
Answers (1)
  1. 1 October, 21:17
    0
    Remove the && and create a nested if statement.

    Explanation:

    The statement ((average > 79 && average < = 89)) states a condition that the value of average is supposed to be greater than 79 and less than equals to 89. Since AND (&&) operator is being used between both the expressions so both should be true to make the condition evaluate to true. This means that value of average variable is greater than 79 AND less than or equal to 89.

    Now the logical operator && can be eliminated by using nested-if statement which refers to the if statement inside another if statement. So the above statement can be written as:

    if (average>79)

    {

    if (average<=89)

    }

    It will check firstly the average value for being greater than 79 (if average value is greater than 79?) AND then check average value to see if that less than or equal to 89.

    Usually in nested if statement there is an else part at the end which is executed in case all the if conditions evaluates to false.

    It will be written like this:

    if (average>79)

    { if (average<=89)

    { / *some block of the code to be executed in case the above two if conditions evaluate to true * / } }

    else

    { / /executed if both the above if conditions evaluate to false.}
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “How can the compound conditional expression ((average > 79 && average < = 89)) be written to eliminate the logical operator - without ...” in 📙 Chemistry if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers