C++ Tic Tac Toe - A draw?
Helle everyone, doing a project in school and i'm quite bad at C++. I've made a game of Tic Tac Toe with some inspiration from the internet. Well, i've run into a problem which is most likely easily fixed (assuming you know what you're doing unlike me), regarding the detection of a draw. The program recognises if X or O wins, but not if it's a draw, and everytime i've attempted to fix it i've messed it up.
Suggestions on how to complete the code? And critique of my poor coding is also welcome :) (also, disregard the comments that are in danish)
This simply checks if there's a winner yet, if X has won it returns 1, if O wins it returns 2. The game ends correctly when the right values are returned, but i can't find a way of returning 3 when it's a draw without ruining the game (By making the program think if there's no winner it's a draw. That of course results in the program thinking it's a draw as soon as someone makes the first move without winning).
Code:
int checkWinner()
{
//Checker om X har vundet
if(board[0][0] == 'X' && board[0][1] == 'X' && board[0][2] == 'X')
return 1;
if(board[1][0] == 'X' && board[1][1] == 'X' && board[1][2] == 'X')
return 1;
if(board[2][0] == 'X' && board[2][1] == 'X' && board[2][2] == 'X')
return 1;
if(board[0][0] == 'X' && board[1][0] == 'X' && board[2][0] == 'X')
return 1;
if(board[0][1] == 'X' && board[1][1] == 'X' && board[2][1] == 'X')
return 1;
if(board[0][2] == 'X' && board[1][2] == 'X' && board[2][2] == 'X')
return 1;
if(board[0][0] == 'X' && board[1][1] == 'X' && board[2][2] == 'X')
return 1;
if(board[2][0] == 'X' && board[1][1] == 'X' && board[0][2] == 'X')
return 1;
//Checker om O har vundet
if(board[0][0] == 'O' && board[0][1] == 'O' && board[0][2] == 'O')
return 2;
if(board[1][0] == 'O' && board[1][1] == 'O' && board[1][2] == 'O')
return 2;
if(board[2][0] == 'O' && board[2][1] == 'O' && board[2][2] == 'O')
return 2;
if(board[0][0] == 'O' && board[1][0] == 'O' && board[2][0] == 'O')
return 2;
if(board[0][1] == 'O' && board[1][1] == 'O' && board[2][1] == 'O')
return 2;
if(board[0][2] == 'O' && board[1][2] == 'O' && board[2][2] == 'O')
return 2;
if(board[0][0] == 'O' && board[1][1] == 'O' && board[2][2] == 'O')
return 2;
if(board[2][0] == 'O' && board[1][1] == 'O' && board[0][2] == 'O')
return 2;
I'd like it to return 3 if there's a draw. Help plx?
Also i'm new to the forum. Hi everyone!