Thread: Conditional IF Brain Fart

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

    Thumbs down Conditional IF Brain Fart

    In trying to check that R, G, B gives white then would this statement suffice:

    Code:
    if (R == G == B == 255)
    {
    ....
    }

    Thanks
    Last edited by paulogrady; 04-12-2009 at 11:04 AM.

  2. #2
    Chinese pâté foxman's Avatar
    Join Date
    Jul 2007
    Location
    Canada
    Posts
    404
    No.

    Code:
    if (R == 255 && G == 255 && B == 255)
    {
    }
    I hate real numbers.

  3. #3
    Registered User
    Join Date
    May 2008
    Posts
    28

    Thumbs up

    Thanks for the fast answer !

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    No, you are looking to use ||, e.g., R == 255 || G == 255.

    EDIT:
    Oh yes, since you actually want all three to match 255, then yes && would be correct, not ||.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Making mistakes
    Join Date
    Dec 2008
    Posts
    476
    @Above: As far as I know, white is when (R == 255 && G == 255 && B == 255).

    And like loxman said compare all to 255 or

    if (R == G && G == B && B == 255) ...
    Last edited by Brafil; 04-12-2009 at 11:09 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. brain fart
    By Gardul in forum C++ Programming
    Replies: 6
    Last Post: 10-26-2005, 08:49 AM
  3. Re: Girlfriend Post
    By PsychoBrat in forum A Brief History of Cprogramming.com
    Replies: 57
    Last Post: 05-13-2002, 06:11 AM
  4. Brain fart
    By Govtcheez in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 08-30-2001, 12:40 PM