I need some help with the tutorials

This is a discussion on I need some help with the tutorials within the C++ Programming forums, part of the General Programming Boards category; I was reading the c++ tutorials when I got to the Boolean operators. I kinda got the idea of AND, ...

  1. #1
    Registered User
    Join Date
    Jun 2006
    Location
    CA, USA
    Posts
    4

    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!

  2. #2
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,752
    You are not alone with this problem. You may find your answer in previous threads, but don't reply to them.
    http://cboard.cprogramming.com/searc...earchid=487840
    Boolean algebra appears in lots of places: loops, if conditions, sometimes return statements.

  3. #3
    Registered User
    Join Date
    Jun 2006
    Location
    CA, USA
    Posts
    4

    Thank you

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

    Later!

  4. #4
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    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. #5
    Registered User
    Join Date
    Jun 2006
    Location
    CA, USA
    Posts
    4
    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. #6
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,075
    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.
    Sent from my iPadŽ

  7. #7
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,752
    > 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. #8
    Registered User
    Join Date
    Jun 2006
    Location
    CA, USA
    Posts
    4
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 04-06-2007, 06:10 PM
  2. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 11:39 PM
  3. Wiki for Tutorials
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 08-16-2005, 04:03 PM
  4. CProgramming.com should update their tutorials.
    By PorkyChop in forum C++ Programming
    Replies: 17
    Last Post: 09-19-2004, 11:51 PM
  5. Best way to organize tutorials
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 05-30-2004, 05:41 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21