Help evaluating boolean number and arithmetic operators C++

Click For Summary
SUMMARY

The discussion focuses on evaluating a complex boolean expression in C++: !( ((count<10) || (x=0) ). The key to solving this expression lies in understanding operator precedence and the use of parentheses. Participants emphasize the importance of evaluating the innermost expressions first and suggest constructing an expression tree for clarity. The confusion arises from the combination of 'and' and 'or' operators, which necessitates a systematic approach to determine the overall truth value.

PREREQUISITES
  • Understanding of C++ boolean operators
  • Knowledge of operator precedence in C++
  • Familiarity with logical expressions and their evaluation
  • Ability to construct and interpret expression trees
NEXT STEPS
  • Study C++ operator precedence rules
  • Learn how to construct expression trees for boolean logic
  • Practice evaluating complex boolean expressions in C++
  • Explore debugging techniques for logical expressions in C++
USEFUL FOR

C++ students, software developers, and anyone looking to deepen their understanding of boolean logic and operator evaluation in programming.

ihatecats2014
Messages
30
Reaction score
0

Homework Statement


!( ((count<10) || (x<y)) && (count >=0) )
where count is equal to 0

Homework Equations


i don't think any equations here are necessary except maybe the precedence law

The Attempt at a Solution


they combined 'and' and 'or' which confused the heck out of me. How do i figure out if this is true or false? if there is 'and' operator then wouldn't the whole thing have to be true, but the 'or' component means that only one of the expressions has to be true for the whole thing to be true. I am confused, how do i evaluate this? Do i negate last?
thank you
 
Last edited:
Physics news on Phys.org
To evaluate an expression like this, you need to know the precedence of the involved operators. In this case, parenthesis are heavily used, so you can start by evaluating the inner-most parenthesis containing expressions with "count" and then work your way outward to the next level of parenthesis in succession by employing the logic of the involved operators.

If you loose track of all the parenthesis levels you may benefit from drawing the whole thing up as an expression tree first.
 
that is what my professor told me, just to be sure i have it down, the inner most expression in this case would be the first expression? then the second expression containing count and then the last one?
 

Similar threads

  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 15 ·
Replies
15
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 14 ·
Replies
14
Views
5K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K