Or operator?

This is a discussion on Or operator? within the C++ Programming forums, part of the General Programming Boards category; >> Pop[index][11] = Pop[index][1] This part is wrong. It should be: then Pop[index][11] = 1 and fitness = 1....

  1. #16
    Registered User
    Join Date
    Jan 2005
    Posts
    7,344
    >> Pop[index][11] = Pop[index][1]
    This part is wrong. It should be:

    then Pop[index][11] = 1 and fitness = 1.

  2. #17
    Registered User
    Join Date
    Oct 2005
    Posts
    82
    Perhaps i should have been more clear, but yes.

    If the if statement is true, then Pop[index][11] = 1,

    what i need to know is does this part work as intended:

    (Grid[x-1][y] == 1)

    ie Grid[4][5] equal to 1

  3. #18
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    >> (Grid[x-1][y] == 1)

    Well, if x=5 and y=5, then it should work as intended.

  4. #19
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Code:
    if (Grid[x][++y] != 1 && Grid[x][y] != 0 /*|| Grid[x][y] != 3*/)
    This is a really bad idea. Although, due to the fact that && and || are sequence points, it will actually produce predictable results, it is still hard to read and thus hard to maintain.
    Just increment x/y first and then do the test.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Failure to overload operator delete
    By Elysia in forum C++ Programming
    Replies: 16
    Last Post: 07-10-2008, 02:23 PM
  2. Smart pointer class
    By Elysia in forum C++ Programming
    Replies: 63
    Last Post: 11-03-2007, 08:05 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  4. Operator Overloading (Bug, or error in code?)
    By QuietWhistler in forum C++ Programming
    Replies: 2
    Last Post: 01-25-2006, 08:38 AM
  5. operator overloading and dynamic memory program
    By jlmac2001 in forum C++ Programming
    Replies: 3
    Last Post: 04-07-2003, 12:51 AM

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