title: C++ Program wont quit, using switch case
body: <p>I'm writing a tic tac toe program that plays throuh the terminal/console
  After Player 1 or 2 wins, I give the choice for the user to play again, 1 = play again, 2 to quit.
  However, entering 2 to quit doesnt work</p>
  
  <pre><code>//tie check, replay, use pointer notation
  #include &lt;iostream&gt;
  using namespace std;
  
  void initialize(char [][3]);
  void player1(char [][3]);
  void player2(char [][3]);
  void display(char [][3]);
  char check(char [3][3]);
  int main()
  {
      char board[3][3];
      char end = '*';
      int row1, column1, row2,column2;
      bool replay = true;
      //replay loop
      do
      {
          //set board to *
          initialize(board);
          //game loop
          display(board);
          do 
          {
              //player 1 turn
              player1(board);
  
              //check if player 1 won
              end = check(board); 
              if(end != '*')
              {
                  int input;
                  /* winner!*/
                  cout &lt;&lt; "Player 1 Won!\n";
                  do
                  {
                      cout &lt;&lt; "Play Again?\n1.Yes\n2.No\nEnter 1 or 2: ";
                      cin &gt;&gt; input;
                      if (input &gt; 2 || input &lt; 1)
                          cout &lt;&lt; "Invalid Option\n";
  
                  }while(input &gt; 2 || input &lt; 1);
  
                  switch (input)
                  {
                      case '1':
                          replay = true;
                          break;
                      case '2':
                          cout &lt;&lt; "Thank you for playing.\n";
                          exit(0);
                          break;
                  }
              }
  
              //player 2 turn
              player2(board);
  
              //check if player 2 won
              end = check(board);
              if (end == 'O')
              {
                  int input;
                  /* winner!*/
                  cout &lt;&lt; "Player 2 Won!\n";
                  do
                  {
                      cout &lt;&lt; "Play Again?\n1.Yes\n2.No\nEnter 1 or 2: ";
                      cin &gt;&gt; input;
                      if (input &gt; 2 || input &lt; 1)
                          cout &lt;&lt; "Invalid Option\n";
                  }while(input &gt; 2 || input &lt; 1);
  
                  switch (input)
                  {
                      case '1':
                          replay = true;
                          break;
                      case '2':
                          cout &lt;&lt; "Thank you for playing.\n";
                          exit(0);
                          break;
                  }
              }
          }while (end == '*');
  
      }while (replay == true);
  
      return 0;
  }
  
  void initialize(char array[][3])
  {
      for (int i = 0;i &lt; 3;i++)
      {
          for (int j = 0;j &lt; 3;j++)
              array[i][j] = '*';
      }
      cout &lt;&lt; "New Game\n";
  }
  
  void player1(char array[][3])
  {
      int row1, column1;
      cout &lt;&lt; "Player 1\nRow: ";
      cin &gt;&gt; row1;
      while (row1 &lt; 0 || row1 &gt; 2)
      {
          cout &lt;&lt; "Enter a number between 0 and 2 for Row:: ";
          cin &gt;&gt; row1;
      }
  
      cout &lt;&lt; "Column: ";
      cin &gt;&gt; column1;
      while (column1 &lt; 0 || column1 &gt; 2)
      {
          cout &lt;&lt; "Enter a number between 0 and 2 for Column: ";
          cin &gt;&gt; column1;
      }
  
      if (array[row1][column1] == '*')
          array[row1][column1] = 'X';
      else
      {
          cout &lt;&lt; "Space Occupied\n";
          player1(array);
      }
      display(array);
  }
  
  void player2(char array[][3])
  {
      int row2,column2;
      cout &lt;&lt; "Player 2\nRow: ";
      cin &gt;&gt; row2;
      while (row2 &lt; 0 || row2 &gt; 2)
      {
          cout &lt;&lt; "Enter a number between 0 and 2 for Row: ";
          cin &gt;&gt; row2;
      }
  
      cout &lt;&lt; "Column: ";
      cin &gt;&gt; column2;
      while (column2 &lt; 0 || column2 &gt; 2)
      {
          cout &lt;&lt; "Enter a number between 0 and 2 for Column: ";
          cin &gt;&gt; column2;
      }
  
      if (array[row2][column2] == '*')
          array[row2][column2] = 'O';
      else
      {
          cout &lt;&lt; "Space Occupied\n";
          player2(array);
      }
      display(array);
  }
  void display(char array[][3])
  {
      for (int x = 0;x &lt; 3;x++)
      {
          for (int y = 0;y &lt; 3;y++)
              cout &lt;&lt; array[x][y] &lt;&lt; " ";
      cout &lt;&lt; endl;
      }
  }
  
  char check(char array[3][3])
  {
      int i;
  
      /* check rows */
      for(i=0; i&lt;3; i++)
          if(array[i][0] == array[i][1] &amp;&amp; array[i][0] == array[i][2]) 
              return array[i][0];
  
      /* check columns */
      for(i=0; i&lt;3; i++)
          if(array[0][i] == array[1][i] &amp;&amp; array[0][i] == array[2][i]) 
              return array[0][i];
  
      /* test diagonals */
      if(array[0][0] == array[1][1] &amp;&amp; array[1][1] == array[2][2])
          return array[0][0];
  
      if(array[0][2] == array[1][1] &amp;&amp; array[1][1] == array[2][0])
          return array[0][2];
  
    return '*';
  }
  </code></pre>