go to previous page   go to home page   hear noise   go to next page

Answer:

Yes.

Boolean Expressions with Mixed AND and OR

cash is 0;credit is 26000; debt is 500. The boolean expression is evaluated like this:

cash >= 25000  ||  ( credit >= 25000 && debt < 1000 )

   false       ||  ( credit >= 25000 && debt < 1000 )

   false       ||  (      true       && debt < 1000 )
   
   false       ||  (      true       &&    true     )

   false       ||  (                true            )

              true

Parentheses are used to group the two relational expressions that are to be ANDed. (Since && has higher precedence than ||, the parentheses are not needed, but they don't hurt.) The following expression is not equivalent:

( cash >= 25000  ||  credit >= 25000 ) && debt < 1000 

When boolean expressions contain both && and || correct grouping is important.

QUESTION 14:

Use the (incorrect) boolean expression above to answer this question: You have $50,000 in cash, $100,000 of credit, and $3,000 of debt. Can you buy the car?