Multiple variables

This is a discussion on Multiple variables within the C Programming forums, part of the General Programming Boards category; Would this be ok? Code: if ( a, b, c, d == 1 || a, b, c, d == 2 ...

  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 04:04 AM.

  2. #2
    cwr
    cwr is offline
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    868
    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, 07:03 PM
  2. why Multiple define error ...
    By nilathinesh in forum C Programming
    Replies: 2
    Last Post: 10-19-2006, 06:31 AM
  3. Remotely Creating Variables
    By Rajin in forum C++ Programming
    Replies: 1
    Last Post: 04-26-2005, 11:20 PM
  4. Declaring an variable number of variables
    By Decrypt in forum C++ Programming
    Replies: 8
    Last Post: 02-27-2005, 03:46 PM
  5. Replies: 1
    Last Post: 05-01-2003, 02:52 PM

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