Tic Tac Toe Game
Sep 12, 2012 at 2:25pm UTC
I am trying to initialize the array "board", but whenever I use {} it gives me an error saying it "expects an expression". Please tell me how I can initialize multidimensional dynamic arrays, so that I can print them to the screen.
Here is my code:
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
#include <iostream>
using namespace std;
const int h = 3;
const int w = 3;
enum SpaceState;
enum SpaceState
{
X = 'X' ,
O = 'O' ,
blank = '-'
};
SpaceState** board;
void initBoard()
{
board = new SpaceState*[h];
board[h];
for (int i = 0; i < h; i++)
board[i] = new SpaceState[w];
}
void drawBoard(SpaceState arg[])
{
}
SpaceState getInput()
{
int row;
int column;
cout << "Enter a row to place your piece: " ;
cin >> row;
cout << "Enter a column to place your piece: " ;
cin >> column;
return board[row][column] = X;
}
int main(void )
{
initBoard();
getInput();
delete board[w];
delete board[h];
}
Sep 12, 2012 at 3:33pm UTC
Topic archived. No new replies allowed.