Arrays

Discussion in 'C' started by Xodiox, Jul 3, 2006.

  1. Xodiox

    Xodiox New Member

    Joined:
    Jun 19, 2006
    Messages:
    11
    Likes Received:
    1
    Trophy Points:
    0
    Hi everyone,

    I'm learning how to use arrays in c++ with the Practical C++ Programming book from O'Reilly but now I have run into a problem.

    Im working with Multidimensional arrays ie, n[3][3]. Im trying to make a 3*3 grid that displays any number from 0 - 9 but it's not allowed to have any of the same number. I have managed to get it to check each number in the different rows and columns. So if I have 3 in n[0][0] then the other numbers in row n[0][...] can't be a 3 and the other numbers in column n[...][0] can't be a 3. This part works fine but how can I get it to check that the number in n[0][0] is not the same as the number in n[1][1] or n[2][2] for example.

    I hope that you can follow where i'm going with this. :)

    Thanks
     
  2. coderzone

    coderzone Super Moderator

    Joined:
    Jul 25, 2004
    Messages:
    736
    Likes Received:
    38
    Trophy Points:
    28
    Just checking them in loop for n would solve the isuue.
     
  3. Xodiox

    Xodiox New Member

    Joined:
    Jun 19, 2006
    Messages:
    11
    Likes Received:
    1
    Trophy Points:
    0
    How would I write that ?

    while (x == n) bad = 1;

    or in an if statment ? Or something else ?
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,376
    Likes Received:
    388
    Trophy Points:
    83
    What you have written is something correct but it should be if instead of while.
     
  5. Xodiox

    Xodiox New Member

    Joined:
    Jun 19, 2006
    Messages:
    11
    Likes Received:
    1
    Trophy Points:
    0
    Thanks for the help :D
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice