Trying to make a game with 2d array. Need some help

Hello!

Im trying to make a game with an array.

So the user types in coordinates and "shoots" / guesses the right spot on the array, (haven't put it out yet).
And every try it saves the last attempts.

But when I running this code, it will show me:
1
2
3
4
5
   1 2 3 4
1| 0 0 0 0
2| 0 0 0 0
3| 0 0 0 0
4| 0 0 0 0


I want it to be more like:
1
2
3
4
5
   1 2 3 4
1| *   
2|       *
3| *
4|

Where its blank between the guesses.

How can do this?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
using namespace std;

int main()
{
    const int WIDTH = 4;
    const int HEIGHT = 4;
    int numberLeft = 1;
    int guess;
    bool success;

    int gameBoard[WIDTH][HEIGHT] = {{0,0,0,0},
                                    {0,0,0,0},
                                    {0,0,0,0},
                                    {0,0,0,0}};


    cout << "  1|2|3|4|" <<  endl;
    for(int i = 0; i < WIDTH; i++)
        {

            cout << numberLeft << "|";
            numberLeft++;
            for(int j = 0; j < HEIGHT; j++)
            {
                cout << gameBoard[i][j] << "|";
            }
            cout << endl;
        }
    cout << endl;
    cout << "Enter X-coordinates: " << endl;
    cout << "Enter Y-coordinates: ";
    return 0;
}
Simply replace line 26 with an if statement.
26
27
28
29
    if (gameboard[i][j])
        cout << "* ";  // occupied
    else
        cout << "  ";  // not occupied  



Topic archived. No new replies allowed.