# Thread: Noob getting confused by booleans

1. ## Noob getting confused by booleans

Code:
```A. !( 1 || 0 )         ANSWER: 0	//how is that so?
B. !( 1 || 1 && 0 )    ANSWER: 0 (AND is evaluated before OR) //how is that so?
C. !( ( 1 || 0 ) && 0 )  ANSWER: 1 (Parenthesis are useful)```
In the if statement tutorial i got to the end of it and say these boolean statements and dont under stand how any of those eqaul to false or true
Cause all i see its saying is Not 1 or 0
Not 1 or 1 and 0 // By the way does 1 and 0 make it 10 or is the and function like adding ?

Main question is how is not 1 or 0 eqaul to False When i see no variable around to define wat the number is

thanks for clearing up the and question
but wat im trying to ask is how do i no wat the number is in these 3 questions

2. Um, I suggest you get reading some more tutorials and such and start figuring out some of the more basic stuff yourself since this is only going to get harder.

First thing to understand is that boolean expressions in C++ can also be numeric (and indeed are numeric in reality). The idea is that every number is true except 0. So 1 is true, 2 is true, -1 is true, -500 is true, 0 is false. !0 produces 1, and !1 produces 0.

3. The rule is: zero is false, non-zero is true.

4. The operators && and || are logicial operators, they work on "true or false", that those are the only results you can expect from that. Anything that is not zero is "true", and zero is "false".

1 && 0 says "is 1 _and also_ 0" both true? 1 && 0 therefore is not true, since 0 is not true.

The || operator means "either or" (as opposite of the "or" that we use in natural language, which most commonly means "one but not the other", e.g. "Do you want coke or beer?"). So 1 || 0 is true since one of "1 _either or_ 0" is true.

Human language is not always as logical as computers. I've hear people say "Coffee and tea, anyone?", but they certainly don't mean that we all need to drink both coffee _AND_ tea at the same time (or in sequence, mixed or whatever?), but rather that we have a choice of "coffee" or "tea".

There is also an order or precedence for all operators:
http://en.wikipedia.org/wiki/Operato...tor_precedence

--
Mats

5. I've hear people say "Coffee and tea, anyone?", but they certainly don't mean that we all need to drink both coffee _AND_ tea at the same time (or in sequence, mixed or whatever?), but rather that we have a choice of "coffee" or "tea".
A little off topic, but I know friends who literally like to drink coffee and tea in a mix. When we say "coffee or tea", we usually mean "coffee or tea, but not both" (i.e., exclusive or), but these friends of mine would interpret it as both!

6. I had an old boss (well, a young boss a long time ago) who used to answer all "or" questions" this way, in jest of course:

"Are we going to Fridays or Outback for lunch?"

"Yes"

7. Originally Posted by medievalelks
I had an old boss (well, a young boss a long time ago) who used to answer all "or" questions" this way, in jest of course:

"Are we going to Fridays or Outback for lunch?"

"Yes"
I do that too. Particularly if it's a programmer type person that asks.

--
Mats

8. Nathan,

I think this is difficult because it's abstract. You may need to think in terms of something being true or false, rather than meaningless boolean 1's & 0's... In real programs, the boolean variables represent the state of something.

If you can find a book with some real-world examples, it will probably get easier. This is how computer programs "make decisions" and it's a very basic, very important programing concept. If-statements (with boolean logic) and looping (doing stuff over & over) are the two most important concepts in progamming... These are the things that make programming worthwhile.

If it's lunchtime (lunch = true) AND if I'm hungry (hungry = true), then we are going to Outback for lunch (Outback = true).

Or, something like this - If there is a blank CD in the drive AND the user clicks "burn", then start burning the CD.

P.S.
When you were first learning math, they didn't teach you that 2+2 = 4... They showed you that 2 apples + 2 apples = 4 apples. Now that you understand the concept, you can understand the abstract representation. But in everyday life, you don't use math in an abstract way. The numbers always represent a quantity or "value" of something in particular.