title: How to check for a tie game beginner C++
body: <p>I am creating a tic-tac-toe program and cannot get the game to accurately check if there is a tie.  The tie should be declared when all numbers on the board are filled with 'X' or 'O' &amp; there is no winner.</p>
  
  <p>With the code I have now, every time I run the program it declares there is a tie.  Am I placing the function wrong?  I think something is wrong INSIDE of the <code>tieGame()</code> boolean.</p>
  
  <pre><code>using namespace std;
  
  char board[9] { //array of characters with number placeholders for chars X and O
      '1', '2', '3', '4', '5', '6', '7', '8', '9'
  };
  
  bool checkWinner(void) {
      bool winner = false;
      if // Check for possible winning solutions for X
      ((board[0] == 'X' &amp;&amp; board[1] == 'X' &amp;&amp; board[2] == 'X')
      ||
      (board[3] == 'X' &amp;&amp; board[4] == 'X' &amp;&amp; board[5] == 'X')
      ||
      (board[6] == 'X' &amp;&amp; board[7] == 'X' &amp;&amp; board[8] == 'X')
      ||
      (board[0] == 'X' &amp;&amp; board[4] == 'X' &amp;&amp; board[8] == 'X')
      ||
      (board[2] == 'X' &amp;&amp; board[4] == 'X' &amp;&amp; board[6] == 'X')
      ||
      (board[0] == 'X' &amp;&amp; board[3] == 'X' &amp;&amp; board[6] == 'X')
      ||
      (board[1] == 'X' &amp;&amp; board[4] == 'X' &amp;&amp; board[7] == 'X')
      ||
      (board[2] == 'X' &amp;&amp; board[5] == 'X' &amp;&amp; board[8] == 'X'))
      {
          winner = 1; // Winner is true if conditions are met
          cout &lt;&lt; "Player 1 Wins!" &lt;&lt; endl;
      }
      else if // Check for possible winning solutions for O
      ((board[0] == 'O' &amp;&amp; board[1] == 'O' &amp;&amp; board[2] == 'O')
      ||
      (board[3] == 'O' &amp;&amp; board[4] == 'O' &amp;&amp; board[5] == 'O')
      ||
      (board[6] == 'O' &amp;&amp; board[7] == 'O' &amp;&amp; board[8] == 'O')
      ||
      (board[0] == 'O' &amp;&amp; board[4] == 'O' &amp;&amp; board[8] == 'O')
      ||
      (board[2] == 'O' &amp;&amp; board[4] == 'O' &amp;&amp; board[6] == 'O')
      ||
      (board[0] == 'O' &amp;&amp; board[3] == 'O' &amp;&amp; board[6] == 'O')
      ||
      (board[1] == 'O' &amp;&amp; board[4] == 'O' &amp;&amp; board[7] == 'O')
      ||
      (board[2] == 'O' &amp;&amp; board[5] == 'O' &amp;&amp; board[8] == 'O'))
      {
          winner = 1; // winner is True if conditions are met
          cout &lt;&lt; "Player 2 Wins!" &lt;&lt; endl;
      }
      return winner; // Is there a winner?
  
  }
  
  bool tieGame() {
      bool tiegame = false;
      if // check for tie
          ((board[0] == 'X' || 'O') &amp;&amp; (board[1] == 'X' || 'O') &amp;&amp; (board[2] == 'X' || 'O')
           &amp;&amp;
           (board[3] == 'X' || 'O') &amp;&amp; (board[4] == 'X' || 'O') &amp;&amp; (board[5] == 'X' || 'O')
           &amp;&amp;
           (board[6] == 'X' || 'O') &amp;&amp; (board[7] == 'X' || 'O') &amp;&amp; (board[8] == 'X' || 'O'))
      {
          tiegame = 1;
          cout &lt;&lt; "The game is a tie!  Play again!" &lt;&lt; endl;
      }
      else {
          tiegame = 0;
      }
      return tiegame; //  Is the game a tie?
  }
  
  
  void displayBoard(void) { //Displays the game board
      int index; // used to access the array
      index = 0;
      cout &lt;&lt; endl;
      cout &lt;&lt; board[index] &lt;&lt; "|" &lt;&lt; board[index+1] &lt;&lt; "|" &lt;&lt; board[index+2] &lt;&lt; endl;
      cout &lt;&lt; "-----" &lt;&lt; endl;
      cout &lt;&lt; board[index+3] &lt;&lt; "|" &lt;&lt; board[index+4] &lt;&lt; "|" &lt;&lt; board[index+5] &lt;&lt; endl;
      cout &lt;&lt; "-----" &lt;&lt; endl;
      cout &lt;&lt; board[index+6] &lt;&lt; "|" &lt;&lt; board[index+7] &lt;&lt; "|" &lt;&lt; board[index+8] &lt;&lt; endl;
  }
  
  void tictactoe(void) { //Main function; displays board and inputs player moves
      int movePosition; // used to track user input and replace array indexes with the user input
  
      cout &lt;&lt; "Player 1 is X, player 2 is O" &lt;&lt; endl;
      for (int i=0; i &lt; 5; i++) {
          if (tieGame() ) {
              cout &lt;&lt; "Tie game!" &lt;&lt; endl;
              return;
          }
          displayBoard(); // Display game board with updated characters
          if (checkWinner() ) //if winner is TRUE, return "Winner" and exit game.
              {
                  cout &lt;&lt; "Good Game!" &lt;&lt; endl;
                  return;
              }
          cout &lt;&lt; "Player 1, Enter the space number where you would like to place X" &lt;&lt; endl;
          cin &gt;&gt; movePosition; // Retrieve user input &amp; call it 'movePosition'
              while ((board[movePosition - 1] == 'X' || board[movePosition - 1] == 'O')) {       //Check to make sure a user has not
                  cout &lt;&lt;  "This space is already taken.  Please choose an open space." &lt;&lt; endl; // attempted to enter a
                  cin &gt;&gt; movePosition;                                                           // value that has already been entered
              }
          board[movePosition - 1] = 'X';
          displayBoard(); // Display game board with updated characters
              if (checkWinner() ) //if winner is TRUE, return "Winner" and exit game.
              {
                  cout &lt;&lt; "Good Game!" &lt;&lt; endl;
                  return;
              }
          cout &lt;&lt; "Player 2, Enter the space number where you would like to place O" &lt;&lt; endl;
          cin &gt;&gt; movePosition;
  
              while ((board[movePosition - 1] == 'X' || board[movePosition - 1] == 'O')) {
                  cout &lt;&lt; "This space is already taken.  Please choose an open space." &lt;&lt; endl;
                  cin &gt;&gt; movePosition;
              }
          board[movePosition - 1] = 'O';
      }
  }
  
  
  
  int main (int argc, char *argv[]) {
      tictactoe();
  }
  </code></pre>