# Thread: I need some help with the tutorials

1. ## I need some help with the tutorials

I was reading the c++ tutorials when I got to the Boolean operators. I kinda got the idea of AND, OR, and NOT (&&, ||, and !).
Well, to tell the truth, I barely got it at all...
Worse is that I dont even know how to use them. The sample code looks like this:
Code:
```
A. !( 1 || 0 )         ANSWER: 0
B. !( 1 || 1 && 0 )    ANSWER: 0 (AND is evaluated before OR)
C. !( ( 1 || 0 ) && 0 )  ANSWER: 1 (Parenthesis are useful)```
How do I put that into a program? It said it would be simple, but I need help...

Thanks!

http://cboard.cprogramming.com/searc...earchid=487840
Boolean algebra appears in lots of places: loops, if conditions, sometimes return statements.

3. ## Thank you

Thanks. Ill be sure to read them and try to understand them. I wont reply.

Later!

4. Well, to tell the truth, I barely got it at all...
Worse is that I dont even know how to use them.
I suppose the hard part is the abstraction... Getting used to using true & false without saying what is true, or what is false, and getting used to the idea that true is represented by 1 (or a non-zero value) and false is represented by zero.

It gets a little easier when you are working with something more concrete... IF the user clicks "burn" AND (There is a blank CD in the drive OR there is a blank DVD in the drive)...

Maybe it's easier to think "condition true" and "condition false", than simply "true" and "false".

At some point, you have to get used to using these concepts abstractly. It might seem weird to say "True AND False equals False", but after you work with it awhile it will become more natural. When/if you start working with bitwise operators, you will be using boolean logic directly with binary 1's and 0's.

I learned this stuff with truth tables. I found a truth table link, but I'm not sure how helpful it is because it uses different termonology and different symbols... more abstraction.

A basic truth table shows 4 possible conditions and the result.. something like this:

The AND truth table (A AND B = Result)
F AND F = F
F AND T = F
T AND F = F
T AND T = T

The AND truth table with 1's & 0's
0 AND 0 = 0
0 AND 1 = 0
1 AND 0 = 0
1 AND 1 = 1

If you substitute something concrete... Let's say:
A = click burn
B = blank CD in drive
Result = burn CD

The only way you can burn a CD is if both A and B are true. With the other 3 conditions, the result is result is false.

5. Now, by 1 and 0, you dont mean the result in an equation, right?

For example, 1+0=1, but that doenst necessarily make it TRUE. 1-1=0 isnt FALSE.
Is that correct?
If my question confuses you, Ill try to clear it up in another way. :/

6. He's speaking in terms of boolean values, not the equation in whole.
Code:
`1 - 1 = 0`
would say that a value minus itself results in a false boolean value. You want to see the right value as the result the condition on the left gives you. Not as part of the equation. For instance:
Code:
```// when he writes ( 1 - 1 = 0 )
// you should view a conditional with the left value as the whole condition

if(1 - 1) // Returns a boolean false

// as opposed to the whole thing as the condition

if(1 - 1 == 0) // This as you said, is not false```
You see? I hope I understood your question correctly.

7. > For example, 1+0=1, but that doenst necessarily make it TRUE. 1-1=0 isnt FALSE.
> Is that correct?
Yes, but you are missing the point. Arithmatic is completely different from boolean algebra. The logical operators do not change the terms they are used on, they merely evaluate the truth or falsehood of a statement.
1 && 1 = true
0 && 1 = false
0 && 1 || 1 = true (logical and is evaluated before or)
!(1 && 0 || 1) = false

8. I think I get it now. Sorry, its just that before this, I never even heard of Boolean Algebra... Ill try rereading the lesson along with this information and maybe I can understand it better.
Thanks.