Thread: Multiple variables

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    19

    Multiple variables

    Would this be ok?

    Code:
    if ( a, b, c, d == 1  || a, b, c, d == 2 || a, b, c, d == 3 || a, b, c, d == 4 || a, b, c, d == 5 ) {
    Or is this wrong with int a, b, c, d;
    Last edited by Kaho; 08-18-2005 at 05:04 AM.

  2. #2
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    It's valid C, but it won't do what you expect. You would need to test each individual case...
    Code:
    if ( (a == 1 && b == 1 && c == 1 && d ==1) || (a == 2 && b == 2 && c == 2 && d == 2) ...
    The comma operator cannot be used in the way you describe.

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    19
    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. comparing multiple variables..
    By myrddin in forum C Programming
    Replies: 9
    Last Post: 10-16-2007, 08:03 PM
  2. why Multiple define error ...
    By nilathinesh in forum C Programming
    Replies: 2
    Last Post: 10-19-2006, 07:31 AM
  3. Remotely Creating Variables
    By Rajin in forum C++ Programming
    Replies: 1
    Last Post: 04-27-2005, 12:20 AM
  4. Declaring an variable number of variables
    By Decrypt in forum C++ Programming
    Replies: 8
    Last Post: 02-27-2005, 04:46 PM
  5. Replies: 1
    Last Post: 05-01-2003, 03:52 PM
Website Security Test