title: Logical Mistakes, Checking for a Winner in Tic Tac Toe
body: <p>Alright, so I am incredibly close to finishing this program. I understand why my program wasn't making a move and I was able to fix it, but now I am trying to check for a winner. I realize that my <code>winGame()</code> function should be in some sort of while or do while loop to end the game. But, when I was trying to do a little debugging to sort some things out, I realize something unsettling. It always says that it's a draw, even when it's not supposed to be. These are such minor things that I am ashamed to not understand and I would really like some assistance on how I can fix it. Also, I know there's supposed to be a while or do while loop to end the game if there's a win. I'm just unsure where to put it, so if you have any suggestions, please let me know. </p>
  
  <p>*Note that in my valid move function there's a little array, I plan on making it a static const array. My get functions return the value in the name (e.g. getIval() returns the initial value of the cell object), while my set functions just assign the values appropriately.</p>
  
  <pre><code>bool TicTacToe::validMove(char move){
      char options[9] = { '1','2', '3', '4','5','6','7', '8','9' };
      bool validate = false;
      for ( int i = 0; i &lt; 9; i++ ){
          if ( move == options[i]){
              validate = true;
          }
      }
  
      return ( validate );
  }
  
  void TicTacToe::setMove( char move ){
      for ( int i = 0; i &lt; ROW; i++ ){
          for ( int j = 0; j &lt; COL; j++ ){
              if ( board[i][j].getiVal() == move ){
                  board[i][j].setiVal( players[currentPlayer].getMarker() );
                  switchPlayer();
                  break;
              }
          }
      }
  }
  
  void TicTacToe::makeAMove(){
      char move;
      int turns = 1;
      bool validate = true;
  
      do{
          cout &lt;&lt; "Player " &lt;&lt; (getCurrentPlayer() + 1) &lt;&lt; " make a move." &lt;&lt; endl;
          cin &gt;&gt; move;
  
          if ( validMove( move ) ){
              if ( turns &gt; 4 ){
                  cout &lt;&lt; "Nested if-else statement." &lt;&lt; endl;
                  winGame();
                  setMove( move );
              }
              else
                  setMove(move);
          }
          else{
              cout &lt;&lt; "Invalid Move. Please reenter." &lt;&lt; endl;
              cin &gt;&gt; move;
          }
  
          DrawBoard();
          turns++;
  
      } while ( turns &lt;= 9 );   
  }
  
  bool TicTacToe::winGame(){
      cout &lt;&lt; "Calling winGame() "  &lt;&lt; endl;
      bool validate = false;
      int k = 0;
      for ( int i = 0; i &lt; COL; i++ ){
          //check column wins
          if ( board[0][i].getMarker() == board[1][i].getMarker() &amp;&amp; board[1][i].getMarker() == board[2][i].getMarker() &amp;&amp; board[2][i].getMarker() != (' ')){
              cout &lt;&lt; "Column win " &lt;&lt; endl;
              validate = true;
              break;
          }
          //check row wins
          else if ( board[i][0].getMarker() == board[i][1].getMarker() &amp;&amp; board[i][1].getMarker() == board[i][2].getMarker() &amp;&amp; board[i][2].getMarker() !=  (' ')){
              cout &lt;&lt; "Row win." &lt;&lt; endl;
              validate = true;
              break;
          }
      }
  
      if( board[0][0].getMarker() == board[1][1].getMarker() &amp;&amp; board[1][1].getMarker() == board[2][2].getMarker() &amp;&amp; board[2][2].getMarker() != (' ')){
          cout &lt;&lt; "Diagonal 1" &lt;&lt; endl;
          validate = true;
      }
      else if ( board[0][2].getMarker() == board[1][1].getMarker() &amp;&amp; board[1][1].getMarker() == board[2][0].getMarker() &amp;&amp; board[2][0].getMarker() != (' ') ){
          cout &lt;&lt; "Diagonal 2 " &lt;&lt; endl;
          validate = true;
      }
      else{
          cout &lt;&lt; "It's a draw!" &lt;&lt; endl;
          validate = true;
      }
  
      return (validate);
  }
  </code></pre>
  
  <p>Here is a sample run of the program for your reference.</p>
  
  <pre><code>    //sample run
  +--+--+--+
  |1 |2 |3 |
  +--+--+--+
  |4 |5 |6 |
  +--+--+--+
  |7 |8 |9 |
  +--+--+--+
  Player 1 make a move.
  1
  
  +--+--+--+
  |X |2 |3 |
  +--+--+--+
  |4 |5 |6 |
  +--+--+--+
  |7 |8 |9 |
  +--+--+--+
  Player 2 make a move.
  2
  
  +--+--+--+
  |X |O |3 |
  +--+--+--+
  |4 |5 |6 |
  +--+--+--+
  |7 |8 |9 |
  +--+--+--+
  Player 1 make a move.
  3
  
  +--+--+--+
  |X |O |X |
  +--+--+--+
  |4 |5 |6 |
  +--+--+--+
  |7 |8 |9 |
  +--+--+--+
  Player 2 make a move.
  5
  
  +--+--+--+
  |X |O |X |
  +--+--+--+
  |4 |O |6 |
  +--+--+--+
  |7 |8 |9 |
  +--+--+--+
  Player 1 make a move.
  +--+--+--+
  |X |O |X |
  +--+--+--+
  |4 |O |6 |
  +--+--+--+
  |7 |8 |9 |
  +--+--+--+
  Player 1 make a move.
  7
  Nested if-else statement.
  Calling winGame()
  It's a draw!
  
  +--+--+--+
  |X |O |X |
  +--+--+--+
  |4 |O |6 |
  +--+--+--+
  |X |8 |9 |
  +--+--+--+
  Player 2 make a move.
  8
  Nested if-else statement.
  Calling winGame()
  It's a draw!
  
  +--+--+--+
  |X |O |X |
  +--+--+--+
  |4 |O |6 |
  +--+--+--+
  |X |O |9 |
  +--+--+--+
  </code></pre>