I made a tic tac toe program, I used one function to check for the win or draw scenario, the code works fine, but I am not allowed to use functions in this task.

This is my code now, works fine now when the function `gameover()` is added:

```
#include <iostream>
using namespace std;

bool gameover();   

char turn = 'X';
bool draw = false;
char board[3][3] = { { '1', '2', '3' }, { '4', '5', '6' }, { '7', '8', '9' } };

int main()
{   
    while (!gameover())
    {
        cout << "\nPlayer 1 [X] --- Player 2 [O]\n\n\n";
        cout << "\t" << board[0][0] << "   " << board[0][1] << "   " << board[0][2] << endl<< endl;
        cout << "\t" << board[1][0] << "   " << board[1][1] << "   " << board[1][2] << endl<< endl;
        cout << "\t" << board[2][0] << "   " << board[2][1] << "   " << board[2][2] << endl<< endl;
        int choice;
        int row = 0, column = 0;

        if (turn == 'X')
            cout << "Player 1 turn [X]: ";
        else if (turn == 'O')
            cout << "Player 2 turn [O]: ";

        cin >> choice;

        switch (choice)
        {
        case 1: row = 0; column = 0; break;
        case 2: row = 0; column = 1; break;
        case 3: row = 0; column = 2; break;
        case 4: row = 1; column = 0; break;
        case 5: row = 1; column = 1; break;
        case 6: row = 1; column = 2; break;
        case 7: row = 2; column = 0; break;
        case 8: row = 2; column = 1; break;
        case 9: row = 2; column = 2; break;
        default:
            cout << "\nYou didn't enter a correct number! Try again\n";
            continue;
        }

        if (turn == 'X' && board[row][column] != 'X' && board[row][column] != 'O')
        {
            board[row][column] = 'X';
            turn = 'O';
        }
        else if (turn == 'O' && board[row][column] != 'X' && board[row][column] != 'O')
        {
            board[row][column] = 'O';
            turn = 'X';
        }
        else
        {
            cout << "\nThe cell you chose is used! Try again\n";
            continue;
        }
        gameover();
    }

    if (turn == 'O' && !draw)
        cout << endl << endl << "Player 1 [X] Wins! Game Over!\n";
        else if (turn == 'X' && !draw)
            cout << endl << endl << "Player 2 [O] Wins! Game Over!\n";
        else
            cout << endl << endl << "It's a draw! Game Over!";

}

bool gameover()
{
    for (int i = 0; i < 3; i++)//Check for a win
        if ((board[i][0] == board[i][1] && board[i][1] == board[i][2]) || (board[0][i] == board[1][i] && board[1][i] == board[2][i]) || (board[0][0] == board[1][1] && board[1][1] == board[2][2]) || (board[0][2] == board[1][1] && board[1][1] == board[2][0]))
            return true;

    for (int i = 0; i < 3; i++)//Check for draw
        for (int j = 0; j < 3; j++)
            if (board[i][j] != 'X' && board[i][j] != 'O')
                return false;

    draw = true;
    return true;
}

```

But when I remove the `gameover()` function and add it in the `int main()`, it doesn't check for win or draw, it keeps on showing the display board, the program doesn't end.

How do I add the gameover function in the int main and make it check for win or draw?

EDIT: This is the code I implemented so far, even if there are 3 straight 'X', it still asks for output:

```
#include <iostream>
using namespace std;

bool gameover();   

char turn = 'X';
bool draw = false;
char board[3][3] = { { '1', '2', '3' }, { '4', '5', '6' }, { '7', '8', '9' } };

int main()
{   
    while (draw != true)
    {

        cout << "\nPlayer 1 [X] --- Player 2 [O]\n\n\n";
        cout << "\t" << board[0][0] << "   " << board[0][1] << "   " << board[0][2] << endl<< endl;
        cout << "\t" << board[1][0] << "   " << board[1][1] << "   " << board[1][2] << endl<< endl;
        cout << "\t" << board[2][0] << "   " << board[2][1] << "   " << board[2][2] << endl<< endl;
        int choice;
        int row = 0, column = 0;

        if (turn == 'X')
            cout << "Player 1 turn [X]: ";
        else if (turn == 'O')
            cout << "Player 2 turn [O]: ";

        cin >> choice;

        switch (choice)
        {
        case 1: row = 0; column = 0; break;
        case 2: row = 0; column = 1; break;
        case 3: row = 0; column = 2; break;
        case 4: row = 1; column = 0; break;
        case 5: row = 1; column = 1; break;
        case 6: row = 1; column = 2; break;
        case 7: row = 2; column = 0; break;
        case 8: row = 2; column = 1; break;
        case 9: row = 2; column = 2; break;
        default:
            cout << "\nYou didn't enter a correct number! Try again\n";
            continue;
        }

        if (turn == 'X' && board[row][column] != 'X' && board[row][column] != 'O')
        {
            board[row][column] = 'X';
            turn = 'O';
        }
        else if (turn == 'O' && board[row][column] != 'X' && board[row][column] != 'O')
        {
            board[row][column] = 'O';
            turn = 'X';
        }
        else
        {
            cout << "\nThe cell you chose is used! Try again\n";
            continue;
        }
        for (int i = 0; i < 3; i++)//Check for a win
        if ((board[i][0] == board[i][1] && board[i][1] == board[i][2]) || (board[0][i] == board[1][i] && board[1][i] == board[2][i]) || (board[0][0] == board[1][1] && board[1][1] == board[2][2]) || (board[0][2] == board[1][1] && board[1][1] == board[2][0]))
            draw = true;

        for (int i = 0; i < 3; i++)//Check for draw
            for (int j = 0; j < 3; j++)
                if (board[i][j] != 'X' && board[i][j] != 'O')
                    draw = false;
    }

    cout << "The Final Result\n\n\n";
    cout << "\t" << board[0][0] << "   " << board[0][1] << "   " << board[0][2] << endl<< endl;
    cout << "\t" << board[1][0] << "   " << board[1][1] << "   " << board[1][2] << endl<< endl;
    cout << "\t" << board[2][0] << "   " << board[2][1] << "   " << board[2][2] << endl<< endl;

    if (turn == 'O' && !draw)
        cout << endl << endl << "Player 1 [X] Wins! Game Over!\n";
        else if (turn == 'X' && !draw)
            cout << endl << endl << "Player 2 [O] Wins! Game Over!\n";
        else
            cout << endl << endl << "It's a draw! Game Over!";

}

bool gameover()
{
    for (int i = 0; i < 3; i++)//Check for a win
        if ((board[i][0] == board[i][1] && board[i][1] == board[i][2]) || (board[0][i] == board[1][i] && board[1][i] == board[2][i]) || (board[0][0] == board[1][1] && board[1][1] == board[2][2]) || (board[0][2] == board[1][1] && board[1][1] == board[2][0]))
            return true;

    for (int i = 0; i < 3; i++)//Check for draw
        for (int j = 0; j < 3; j++)
            if (board[i][j] != 'X' && board[i][j] != 'O')
                return false;

    draw = true;
    return true;
}

```