Reputation: 93
Hello I am trying to create a tick Tack Toe Game For my College Project, The Board size of the game needs to be GENERIC using 2D array in C++. So I'm having trouble while initializing Default numbers(Places) identifier in an array
for (int i = 0; i < SIZE; i++)
{
for (int j = 0; j < SIZE; j++)
{
Boards[i][j] = initial++;
}
}
for (int i = 0; i < SIZE; i++)
{
for (int j = 0; j < SIZE; j++)
{
if (Boards[i][j] < 10) cout << " " << Boards[i][j] << " | ";
else cout << Boards[i][j] << " | ";
}
cout << endl;
}
As the variable 'initial' is a integer and i have to increment it in loop.I am quite not sure how to save it in char array (BOARD) Board needs to be char to display X,O
Upvotes: 0
Views: 576
Reputation: 87386
Now that you have posted the full code, I can see a problem on this line and the other one like it:
cout << Boards[i][j] << " | ";
Since the type of Boards[i][j]
is a char
, the C++ standard library will just send that char to your terminal, and the terminal will try to interpret it as an ASCII character. You need to cast it to an int
first so that the C++ standard library will format it properly for you:
cout << (int)Boards[i][j] << " | ";
Upvotes: 1