[Solved] Tic Tac Toe using C++ and multidimensional arrays [closed]


Here’s an issue I found:

    int boardcounter = 1;
//...
        for (int j = 0; j < 3; j++)
        {
            board[i][j] = (char) boardcounter;
            boardcounter++;
        }

The issue is that the cast (char) does not convert the int variable into a textual representation. The cast actually converts the integer to smaller sized integer variable.

There are many ways to convert a number to a character, such as snprintf, tostring, and ostringstream.

Since you have a limited range, i.e. digits 0 – 9, you may be able to get away with:

board[row][column] = '0' + boardcounter;

I suggest you review your code and find other places where an integer is being converted to char and change it accordingly.

BTW, most Tic-Tac-Toe games use ‘ ‘, ‘X’ and ‘O’ as values.

1

solved Tic Tac Toe using C++ and multidimensional arrays [closed]