use exit(0)
after checking if player 1 is the winner, to exit the program.
Or, change the function to bool checkWinner()
to be able to return a bool
.
bool checkWinner(void)
{
bool winner = false;
if (board[0] == 'X' && board[1] == 'X' && board[2] == 'X') {
winner = true;
cout << "Player 1 Wins!" << endl;
}
else if (board[0] == 'Y' && board[1] == 'Y' && board[2] == 'Y'){
winner = true;
cout << "Player 2 Wins!" << endl;
}
return winner;
}
In the displayBoard()
function, you can then retrieve the return value, by
if ( checkWinner() )
{
std::cout << "We have a winner" << std::end;
return;
}