Boolean Help

This is a discussion on Boolean Help within the C++ Programming forums, part of the General Programming Boards category; Im having a real hard time understanding how the Boolean operators work and how to figure them out. A. !( ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    4

    Boolean Help

    Im having a real hard time understanding how the Boolean operators work and how to figure them out.

    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)

    like how did u arrive at these answers any help in understanding would b gr8.

    Thanks

  2. #2
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    The power of Wikipedia.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    4
    Thanks I think this might help!

  4. #4
    Registered User
    Join Date
    Sep 2005
    Posts
    1
    My question is how to implement Boolean in an IF statement with YES or NO?

    ("Do you want to re-start? *YES*=restart(for loop?) *NO*=exit")

  5. #5
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    Well, you can't compare strings using the boolean operators. You can only compare numbers.

    In your simple yes / no example, the best option is to check to see if the first character is "Y' or "N". You can use boolean for this, because each ASCII character is represented by a number... you are just comparing numbers.

    You need to understand strings (C-style strings or C++ string objects) and you need to understand the ASCII code.

    Some hints:
    - Check for both upper and lower case.

    - If there are two conditions, you only need to check one... If "yes" is the default answer, just check for "N" or "n". If the user enters anything other than that, assume "yes".

    Even if there are more than 2 choices, I'll usually have a default value so I can just hit ENTER. If there is no default, you need to repeat the question if the user enters something invalid.

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >My question is how to implement Boolean in an IF statement with YES or NO?
    Code:
    do {
    
       //Do stuff
    
       cout << "Do you want to re-start? *YES*=restart *NO*=exit" << flush;
       string answer;
       cin >> answer;
    } while (answer != "no");

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Novice needs help
    By ghaasemi in forum C++ Programming
    Replies: 9
    Last Post: 05-30-2009, 09:20 AM
  2. Casting boolean as string
    By doofusboy in forum C Programming
    Replies: 11
    Last Post: 11-10-2005, 12:24 PM
  3. Replies: 4
    Last Post: 04-02-2004, 07:30 PM
  4. Working with boolean...
    By CompiledMonkey in forum C Programming
    Replies: 4
    Last Post: 11-03-2003, 10:39 AM
  5. Use struct to create a boolean type
    By skyglin in forum C Programming
    Replies: 6
    Last Post: 06-18-2003, 09:21 PM

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