Thread: IF statement

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    82

    IF statement

    I always seem to have trouble getting the right balance on if statements which contain AND's and OR's.

    whats wrong with this

    IF (Env[j] == 1 && POPinit[i][j] == 1 || Env[j] == 1 && POPinit[i][j] == 4)

    basically TRUE when Env = 1 and POPinit is a 1 or 4 aswell.

    But it doesn't seem to work at all any ideas?

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    should add parentheses

    Kuphryn

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    82
    tried that didn't work

  4. #4
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Why not:
    Code:
    if(Env[j] == 1 && (POPinit[i][j] == 1 || POPinit[i][j] == 4))
    Checking Env[j] twice is unnecessary.
    If you understand what you're doing, you're not learning anything.

  5. #5
    Registered User
    Join Date
    Oct 2005
    Posts
    82
    thanks, just realised there may have been a problem earlier on the code.

    int Env[0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,
    0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,
    0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0];

    does this actually create an array Env[180] filled with the above? i'am guessing now it doesn't.

  6. #6
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    Heh...just guessing, but it looks like you're declaring a 0-length array there. The comma operator ignores the lho and returns the rho.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  7. #7
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    You want: int Env[180] = { 0, 0, 1, ......... };
    If you understand what you're doing, you're not learning anything.

  8. #8
    Registered User
    Join Date
    Oct 2005
    Posts
    82
    thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Usefulness of the "else if" statement
    By gn17 in forum C Programming
    Replies: 7
    Last Post: 08-12-2007, 05:19 AM
  2. Meaning of this statement?
    By @nthony in forum C Programming
    Replies: 7
    Last Post: 07-16-2006, 02:57 AM
  3. If Else statement problem
    By doofusboy in forum C Programming
    Replies: 2
    Last Post: 11-09-2005, 07:18 AM
  4. if/break statement
    By Apropos in forum C++ Programming
    Replies: 7
    Last Post: 02-22-2005, 02:33 PM
  5. Uh-oh! I am having a major switch problem!
    By goodn in forum C Programming
    Replies: 4
    Last Post: 11-01-2001, 04:49 PM