tic tac toe code in c++ with two players My main problems are making draw case and any player can choose a place which is chosen by another player here is the code :
#include &lt;iostream&gt;
using namespace std;

char board[3][3] = {{'1', '2', '3'}, {'4', '5', '6'}, {'7', '8', '9'}};
static int turnnumber = 1 ;
bool winner = false, flag = false ;
bool win(){
     if(board[0][0]==board[1][1]&amp;&amp;board[1][1]==board[2][2])
    winner = true ;
    if(board[0][2]==board[1][1]&amp;&amp;board[1][1]==board[2][0])
    winner = true ;
if(board[1][0]==board[1][1]&amp;&amp;board[1][1]==board[1][2])
    winner = true ;
if(board[0][0]==board[0][1]&amp;&amp;board[0][1]==board[0][2])
    winner = true ;
if(board[2][0]==board[2][1]&amp;&amp;board[2][1]==board[2][2])
    winner = true ;    
if(board[0][0]==board[1][0]&amp;&amp;board[1][0]==board[2][0])
    winner = true ;
if(board[0][1]==board[1][1]&amp;&amp;board[1][1]==board[2][1])
    winner = true ;
if(board[0][2]==board[1][2]&amp;&amp;board[1][2]==board[2][2])
    winner = true ;
            
    if(winner==true&amp;&amp;turnnumber==1)
       cout &lt;&lt; &quot;player2 won \n\n&quot; ;
    if(winner==true&amp;&amp;turnnumber==2)
       cout &lt;&lt; &quot;player1 won \n\n&quot; ;
 
    return winner;
}

void view()
{
    for (int i = 0; i &lt; 3; i++)
    {
        for (int x = 0; x &lt; 3; x++)
        {
            cout &lt;&lt; &quot;[&quot; &lt;&lt; board[i][x] &lt;&lt; &quot;]  &quot;;
        }
        cout &lt;&lt; endl
             &lt;&lt; &quot;-------------&quot; &lt;&lt; endl;
    }
}
    
void players()
{
    
    char player1 = 'X', player2 = 'O';
    int number;
    cout &lt;&lt; &quot;\nplayer &quot; &lt;&lt; turnnumber &lt;&lt; &quot; it's your turn &quot;;
    if(turnnumber==1)
       turnnumber++;
    else if(turnnumber==2)
       turnnumber--;
    char player;
    if(turnnumber==1)
       player=player2;
    if(turnnumber==2)
       player=player1;
    cin &gt;&gt; number ;
    
    switch(number){
        
    case 1:
        board[0][0] = player;
        break;
    case 2:
        board[0][1] = player;
        break;
    case 3:
        board[0][2] = player;
        break;
    case 4:
        board[1][0] = player;
        break;
    case 5:
        board[1][1] = player;
        break;
    case 6:
        board[1][2] = player;
        break;
    case 7:
        board[2][0] = player;
        break;
    case 8:
        board[2][1] = player;
        break;
    case 9:
        board[2][2] = player;
        break;
    default:
        cout &lt;&lt; &quot;\nwrong number\n&quot;;
        players();
         
    }
    system(&quot;cls&quot;);
    view();
 
    if(!win())
        players();
}

int main()
{
    view();
    players();
}
You can address both of the your problems using &quot;struct&quot;.
By making something like this:
struct myBorad 
{
    char board[3][3] = { {'1', '2', '3'}, {'4', '5', '6'}, {'7', '8', '9'} };
    bool bMyBoardStatus[9] = { false };
};
myBorad g_myBoard;

You then need to change each of the fields as &quot;taken&quot; by setting them to &quot;true&quot;.
after each player play.
g_myBoard.bMyBoardStatus[0] = true;

Now that you have this in place you can add two ifs:

Check if the status of selected by player place is &quot;taken&quot; aka not false.
Check if all the array aka all nine of them are true and you didn't meet the win condition yet that means its draw.

there are more elegant solutions but this will help you get what you need, and this does not have to be in struct. i prefer this way.