title: Tic tac toe game code
body: <p>Good evening everyone, could anyone point me in the direction I need to go to get this code for a simple game of tic tac toe operational? I feel it is very close but I cannot get it to behave properly. Also, what could I use instead of break commands under the drawBoard command? Thanks in advance..</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  
  
  // This program allows user(s) to play a game of tic-tac-toe.
  
  
  using namespace std;
  
  // constants
  const char SIGIL[3] = { '.', 'X', 'O' };
  
  // prototypes
  int winner(int board[3][3]);
  void drawBoard(int board[3][3]);
  bool isMoveLegal(int board[3][3]);
  bool isGameOver(int board[3][3]);
  
  
  
  // return 1 if player 1 'X' has won
  // return 2 if player 2 'O' has won
  // return 0 if neither player has won
  int winner(int board[3][3]){
      int win = 0;
  
      // Checks for:
      //     X X X
      for (int i = 0; i &lt; 3; i++)
          if (board[i][0] == board[i][1] &amp;&amp; board[i][1] == board[i][2])
              win = board[i][0];
  
      // Checks for:
      // X
      // X
      // X
      for (int i = 0; i &lt; 3; i++)
      if (board[0][i] == board[1][i] &amp;&amp; board[1][i] == board[2][i])
          win = board[0][i];
  
      // Checks for:
      // X                 X
      //   X      or     X
      //     X         X 
      if ((board[0][0] == board[1][1] &amp;&amp; board[1][1] == board[2][2]) ||
          (board[0][2] == board[1][1] &amp;&amp; board[1][1] == board[2][0]))
          win = board[1][1];
  
      return win;
  }
  
  
  // using this board as a guide
  // draw the board using "." for empty squares
  // or 'X' or 'O' for player 1 or player 2
  void drawBoard(int board[3][3]){
  
  cout &lt;&lt; "   0  1  2" &lt;&lt; endl;
  for (int i = 0; i &lt; 3; i++){
      cout &lt;&lt; i ;
  
  
      for (int j = 0; j &lt; 3; j++){
          cout.width(3);
          switch (board[i][j])
          {
          case 0:{
                     cout &lt;&lt; ".";
          }break; case 1:{
                     cout &lt;&lt; "X";
          }break;
          case 2:{
                     cout &lt;&lt; "0";
          }break;
          default:
              break;
          }
      } cout &lt;&lt; endl;
  }
  
  
  }
  
  
  // return false if row or column are out of bounds
  // or if that spot on the board is already taken 
  // otherwise return true
  bool isMoveLegal(int board[3][3], int row, int column){
  if (row &gt;= 0 &amp;&amp; row &lt;= 3 &amp;&amp; column &lt;= 3 &amp;&amp; column &gt;= 0)     {
      if (board[row][column] == 0)
          return true;
      else return false;
  }
  return false;
  }
  
  
  // if any player has three in a row or if the board is full
  // return true otherwise return false
  bool isGameOver(int board[3][3]){
      if (winner(board) == 1 || winner(board) == 2) return true;
      for (int r = 0; r &lt;= 2; r++)
      for (int c = 0; c &lt;= 2; c++)
      if (board[r][c] == 0)
          return false;
      return true;
  }
  
  
  int main(){
  int board[3][3] = { { 0 } }; // 0 for empty square, 1 or 2 for taken squares
  int player = 1;
  int row, column, result;
  bool legalMove;
  
  // starting board
  drawBoard(board);
  while (!isGameOver(board)){
      cout &lt;&lt; "Player " &lt;&lt; player &lt;&lt; "(" &lt;&lt; SIGIL[player] &lt;&lt; "), your move?";
      cin &gt;&gt; row &gt;&gt; column;
      legalMove = isMoveLegal(board, row, column);
      while (!legalMove){
          cout &lt;&lt; "Player " &lt;&lt; player &lt;&lt; "(" &lt;&lt; SIGIL[player] &lt;&lt; "), your move?";
          cin &gt;&gt; row &gt;&gt; column;
          legalMove = isMoveLegal(board, row, column);
      }
      board[row][column] = player;
      drawBoard(board);
      player = 3 - player;
  }
  // game over
  result = winner(board);
  if (result == 0){
      cout &lt;&lt; "Tie Game" &lt;&lt; endl;
  }
  else {
      cout &lt;&lt; "Player " &lt;&lt; result &lt;&lt; "(" &lt;&lt; SIGIL[result] &lt;&lt; ") wins!" &lt;&lt; endl;
  }
  
  return 0;
  </code></pre>
  
  <p>}</p>