Help evaluating boolean number and arithmetic operators C++

In summary, the conversation is discussing how to evaluate the expression !( ((count<10) || (x<y)) && (count >=0) ) where count is equal to 0. The person is confused about the use of 'and' and 'or' operators and how to determine if the expression is true or false. The solution is to follow the order of precedence and evaluate the inner-most parenthesis first, then work outward using the logic of the operators. Drawing the expression as a tree can also help with keeping track of the levels of parenthesis.
  • #1
ihatecats2014
30
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
  • #2
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.
 
  • #3
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?
 

Related to Help evaluating boolean number and arithmetic operators C++

1. What are boolean operators in C++?

Boolean operators in C++ are symbols that are used to perform logical operations on boolean values. These operators include && (logical AND), || (logical OR), and ! (logical NOT).

2. How do I evaluate a boolean expression in C++?

To evaluate a boolean expression in C++, you can use the if statement. The expression inside the if statement must evaluate to a boolean value, and the code inside the if statement will only be executed if the expression is true.

3. What is the purpose of arithmetic operators in C++?

Arithmetic operators in C++ are used to perform mathematical operations, such as addition, subtraction, multiplication, and division. These operators can be applied to numeric data types, such as integers and floating-point numbers.

4. How do I use arithmetic operators in C++?

To use arithmetic operators in C++, you can simply use the appropriate symbol for the operation you want to perform. For example, to add two numbers, you can use the + operator, and to multiply two numbers, you can use the * operator.

5. Can I combine boolean and arithmetic operators in C++?

Yes, you can combine boolean and arithmetic operators in C++ to create more complex expressions. Just like in mathematics, you can use parentheses to specify the order of operations in your expression. It is important to understand the operator precedence in C++ to ensure that your expressions are evaluated correctly.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
984
Replies
1
Views
909
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
Replies
35
Views
3K
Replies
3
Views
461
  • Engineering and Comp Sci Homework Help
Replies
5
Views
1K
  • Programming and Computer Science
Replies
23
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
11
Views
1K
Back
Top