Having Trouble with boolean

This is a discussion on Having Trouble with boolean within the C++ Programming forums, part of the General Programming Boards category; Hey guys i've just started learning C++ and im stuck with boolean in the tutorial it shows: Code: A. !( ...

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    2

    Having Trouble with boolean

    Hey guys

    i've just started learning C++ and im stuck with boolean

    in the tutorial it shows:


    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)
    When i put one of these in Dev-C++ tells me: expected unqualified-id before '!' token

    if someone could tell me what i am doing wrong it would be great.

    Thanks

    P.S sorry huys, i accidently posted this twice
    My apologies
    Last edited by jazza_rockz; 05-13-2008 at 04:37 AM. Reason: had to apologise for posting twice

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,739
    What did you try? This works for me:
    Code:
    #include <iostream>
    
    int main()
    {
        std::cout << !( 1 || 0 ) << std::endl;
    }
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    May 2008
    Posts
    2
    Now that i look at it, i havent actually gotten as far as std::cout << !( 1 || 0 ) << std::endl;
    so i don't exactly know what it is im doing.

    is there any other way to do it?
    Last edited by jazza_rockz; 05-13-2008 at 04:41 AM.

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,614
    Sure,
    bool b = !( 1 || 0 );

    You must assign the expression somewhere, though.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,739
    is there any other way to do it?
    Eh, your idea is to evaluate the expression and print out the result to see for yourself, right? Then it is as simple as that. What else did you have in mind?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Post your code that isn't working...

  7. #7
    Registered User delgelato's Avatar
    Join Date
    Jun 2008
    Posts
    1
    Emm I just started learning C++, and programming in general, but anyways hello nice to meet you all.

    Anyways, I happen to get the same problem as the TS, I think what he's trying to say is how to apply the boolean operator in an IF statement.

    Well, at least thats where my problem is.

    I tried:

    Code:
    if(age > 20 &#37;% age < 25)
    To make if the input is more than 20 and less than 25 but its still doesn't work.

    edit:
    LOL sorry to bother you it's supposed to be &&, the font makes it hard to see the difference >_< and I never look at what I press so...Anyways I found the problem >_>

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, 08:20 AM
  2. Bolean Operators hurt my head. (Trouble understanding) :(
    By Funcoot in forum C++ Programming
    Replies: 3
    Last Post: 01-20-2008, 06:42 PM
  3. Replies: 4
    Last Post: 04-02-2004, 06:30 PM
  4. Use struct to create a boolean type
    By skyglin in forum C Programming
    Replies: 6
    Last Post: 06-18-2003, 08:21 PM

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