What is wrong with this single if statement?

This is a discussion on What is wrong with this single if statement? within the C Programming forums, part of the General Programming Boards category; I have been staring at this line of code for an hour, I just can't see anything wrong with it? ...

  1. #1
    Registered User javaeyes's Avatar
    Join Date
    Feb 2012
    Posts
    153

    What is wrong with this single if statement?

    I have been staring at this line of code for an hour, I just can't see anything wrong with it? Compiler says 31: expected a , before or.

    Code:
    if ( (tempoption->style == 1) or (tempoption->style == 2) or (tempoption->style == 3) or (tempoption->style == 4) or (tempoption->style == 5) )
    {
    // DO STUFF;
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,409
    If you want to use or instead of || then you should #include <iso646.h>. For the most part, I don't see the point.
    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 javaeyes's Avatar
    Join Date
    Feb 2012
    Posts
    153
    As always, you rock. But 'and' is OK? Or should I use &. ?.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,409
    Quote Originally Posted by javaeyes
    But 'and' is OK? Or should I use &.
    Same thing as or. Also, the normal version of and is &&. The alternative version of & is bitand. My take is that unless you have some very special reasons to use the stuff in <iso646.h>, don't.
    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

  5. #5
    Registered User javaeyes's Avatar
    Join Date
    Feb 2012
    Posts
    153
    Thanks Laser.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what's wrong while statement
    By gamer in forum C++ Programming
    Replies: 3
    Last Post: 05-06-2004, 03:18 AM
  2. Combine code into a Single statement
    By srlien24 in forum C Programming
    Replies: 2
    Last Post: 12-12-2003, 11:47 AM
  3. What's wrong with this IF-statement?
    By kinghajj in forum C++ Programming
    Replies: 6
    Last Post: 11-12-2003, 05:49 AM
  4. What is wrong with this statement???
    By j0hnb in forum C Programming
    Replies: 5
    Last Post: 04-22-2003, 07:03 PM
  5. Something wrong with this if statement?
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 04-30-2002, 05:19 PM

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