TicTacToe

Hi, I'm trying to make a tictactoe program as a project and I can't seem to display my 2D array. Can anyone help??

Here's what I have for my class function:

TTT::TTT()
{
char BoardArray[3][3] = {{'1','2','3'},
{'4','5','6'},
{'7','8','9'}};
}

void TTT::printBoard()
{
cout << endl;
for(int i = 0; i < 3; i++)
{
for(int j = 0; j < 3; j++)
{
cout << " " << BoardArray[i][j] << " ";
if(j == 2)
cout << endl;
}
}
}
Last edited on
In the constructor you are creating a local 2D array that will not exist outside that function. The BoardArray you are accessing in printBoard() is another 2D array.
Is there a way to access elements of the 2D array?
In constructor you declare array char BoardArray[3][3] (it belongs to constructor) - so, you don't modify object's array.

try to do something like it (or write a loop):
1
2
3
4
5
6
7
TTT::TTT()
{
BoardArray[0][0] = '1'; //here you modify the object's array
BoardArray[0][1] = '2';
...
BoardArray[2][2] = '9';
}
It worked! Thanks a lot!! You're a life-saver :D
Topic archived. No new replies allowed.