Tic Tac Toe game in c++

Viewed 35

I wrote an array function name 'getInput' to determine the player's choice. But the program is not running properly even though I wrote the input validation... Can anyone tell me how to revise this funcion?

void getInput(char board[][SIZE], char player)
{

    int row,col;
    bool occupied;
    do
    {
        cout<<"choose a row: ";
        cin>>board[row];
        if(row<1||row>3)
        {
            cout<<"Invalid input.";
            cout<<"choose a row: ";
            cin>>board[row];
        }
        cout<<"choose a column: ";
        cin>>board[col];
        if(col<1||col>3)
        {
            cout<<"Invalid input.";
            cout<<"choose a column: ";
            cin>>board[col];
        }
        if(board[row][col]=='*')
        {
            board[row][col]=player;
            occupied=true;
        }
        else
        {
            cout<<"The spot is taken.\n";
            occupied=false;
        }   
    }while(occupied==false);
}
0 Answers
Related