# Thread: New, and need Boolean help!

1. ## New, and need Boolean help!

I just started programming and can someone explain the Booleans to me? I know they're the OR,AND, and NOT.
I also know that the NOT operator accepts one input. the AND returns TRUE if both inputs are TRUE and the OR is if either (or both) of the two values it checks are TRUE than it returns TRUE or something like that but the problem is that I don't understand it real well and need some help with this because the site's tutorial isn't helpful enough (neither is the FAQ) I tried searching but all the people seem to know Booleans so all they ask is how to use improved booleans, But someone please explain the BOOLEANS to me.

2. Code:
```p !p
T  F
F  T

p q p&&q
T T   T
T F   F
F T   F
F F   F

p q p||q
T T   T
T F   T
F T   T
F F   F```
There are the truth tables for the boolean operators. Really, just think about it logically. I oftentimes just think about an informal sentence; then, I convert that to a wff (well formed formula) or code.

3. ## But my problem..

But my problem is that I'm not sure how to use the codes and when they are used and why because I am just new to this stuff.

4. ## Boolean examples.

You would use booleans to check for true or false, or possibly more than one answer that needs to be checked for a condition.
For example, checking if a user input is 'a' or 'A' when entering data.

OR example:

cin>>userInput;
if (userInput == 'a' || userInput == 'A')
cout<<"User has input an A";

AND example:

This usually checks two data entries or data values;
Something like: type and quantity?

cin>>type;
cin>>quantity;
if (type == 'h' && quantity == 1)
cout<<quantity<<"hamburger is the amount I want";

I hope this might give a little bit of an insight to what Boolean conditionals might be used for. This is just a very small example, so check with some C++ tutorials or a book for more in-depth reasoning.

5. ## Where can I?

Where can I get a good tutorial with examples other than a book or this site's tutorials?

6. ## Try this.

There are some tutorials at the following site. Go to the tutorials main page and scroll down and click on the beginner tutorials. I don't know how good they are, but they may help. There are a lot of them there, so you might be able to find something that fits your C++ level.
http://www.cpp-home.com

~SilasP

7. Here's another tutorial.
I'm not sure how to use the codes and when they are used and why
Have you learned if-statements and switch-statements yet? These operators are used with decision making logic. I was working on a program a few days ago where I needed to break-out of of a test loop if TestCount > 20 AND if ErrorFlag was FALSE.

When you need boolian logic... you'll know it! You'll use AND and OR, when there is more than one condition to test. There is often more than one way to work-out the logic. In the above example, I could have said keep looping if TestCount <= 20, OR ErrorFlag is TRUE.

Sometimes I use NOT when I want to provide a default response.... I might ask the user to enter "C" OR "Q" for Continue or Quit. If the user enters something that is NOT Q OR q, the program contunues.

8. huhhm, thanks I think I understand what you mean.
but this is what it say's in the tutorial:

NOT: the NOT operator accepts one input; if that input is TRUE, it returns FALSE, and if that input is FALSE, it returns TRUE.

AND: this is another important command; AND returns TRUE if both inputs are TRUE(if 'this'AND 'this' are true)

OR: very useful is the OR statement! If either(or both) of the two values it checks are TRUE then it reurns TRUE.

I think I understand but I need to be sure so can someone please give me a couple examples for each on(Please bare with me cuz I must be a pain in the a\$\$)

9. ## Simplest way I know.

I posted some pretty simple code for OR,AND statements already. So I'm thinking you aren't getting the basic thought process of each.

&& means the conditional AND in code.
|| means the conditional OR in code.

If you want to check if a boat is being rowed in a straight line; meaning both the left and the right oar must be in use or rowing. You would use an AND statement. Also, if that isn't the right answer, you could check to see, using an OR statement; if it is being rowed in a circle (Left or Right being true). The first IF statement will rule out the straight line, so this will proceed to checking for a circle path or no path. Possibly in the way of:

if (leftRow && rightRow)
cout<<"Straight path"; (This will print only if both are true)
else if (leftRow || rightRow)
cout<<"Going in a circle"; (This will print if only one is true)
else
cout<<"Going NOWHERE"; (This will print if neither is true)

This is pretty much as basic as it gets.

~SilasP

10. oh, I get it now thanks a lot I just didn't seem to understand for some reason anyway thanks!

11. ## Good deal.

Glad I could help. I've gotten a lot of help on this message board myself, so it felt good to be able to return the favor to someone who needed help.
~Silas P