2d array question

This is a discussion on 2d array question within the C Programming forums, part of the General Programming Boards category; I working on a game board for a battleship game, this is what I have for the gameboard function: Code: ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Location
    Baltimore Md. USA
    Posts
    58

    Thumbs up 2d array question

    I working on a game board for a battleship game, this is what I have for the gameboard function:
    Code:
    int board [10] [10];
    char water = '~';
    int r, c; //r = rows, c = columns
    
      for (r = 0; r < 10; r++)
        {   for (c = 0; c < 10; c++)
                   printf("  %c  ", water);
               if (c == 10)
                  printf(" \n ");
                      c = 0;   //reset column count to 0
    basically at this point I can print the board but it isn't the board. I could take my array out of this and still have the same result. that isn't good. I am trying to print the board as
    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
    etc. but I also need them to have a value so when a player enters a coordinate 2 3, it will tell if it is a hit or not. I'll use a pointer for that. My question is how to assign coordinates to my array while printing the water on the screen.

    *disclosure: this code is mine (for what it's worth) any help would be appreciated.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Why don't you just use the array index as the coordinates?


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Location
    Baltimore Md. USA
    Posts
    58
    sounds good! thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 12
    Last Post: 11-21-2010, 08:46 AM
  2. My array question
    By kordric in forum C++ Programming
    Replies: 23
    Last Post: 05-03-2008, 10:30 AM
  3. Array Question
    By Octorok101 in forum C++ Programming
    Replies: 3
    Last Post: 05-19-2003, 05:41 PM
  4. array question?
    By correlcj in forum C++ Programming
    Replies: 1
    Last Post: 11-08-2002, 05:27 PM
  5. Array question.
    By Unregistered in forum C Programming
    Replies: 8
    Last Post: 07-08-2002, 01:43 PM

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