Dec 4, 2011 at 10:05pm UTC
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 Dec 4, 2011 at 10:15pm UTC
Dec 4, 2011 at 10:17pm UTC
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.
Dec 4, 2011 at 10:19pm UTC
Is there a way to access elements of the 2D array?
Dec 4, 2011 at 10:25pm UTC
It worked! Thanks a lot!! You're a life-saver :D