title: C++ Array Troubles
body: <p>Im trying to build a tic tac toe game, and for some reason seem to be getting hit by a bug when I try and put a value into any values, it seems to give the selected character(say its player 1, and thus an 'X'), into the values selected by the user(where he wants it to be) but also annoyingly into [1][2] and [2][0] of the array. The code is attached.</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;ctime&gt;
  #include &lt;cstdlib&gt;
  
  using namespace System;
  using namespace std;
  
  string game_board[2][2];
  bool exit_condition = false;
  int x_coords;
  int y_coords;
  int current_player;
  string cp_char;
  
  int returnxwin();
  int returnowin();
  
  int main()
  {
      cout &lt;&lt; "Welcome to Tic-Tac-Toe Console!\n" &lt;&lt; endl;
  
      //Start of game
      while(exit_condition != true){
          cout &lt;&lt; "This is the game board: " &lt;&lt; endl;
          cout &lt;&lt; " - | 1 | 2 | 3 | " &lt;&lt; endl;
          cout &lt;&lt; " 1 | " &lt;&lt; game_board[0][0] &lt;&lt;" | " &lt;&lt;game_board[1][0] &lt;&lt; " | " &lt;&lt; game_board[2][0] &lt;&lt; " | " &lt;&lt;endl;
          cout &lt;&lt; " 2 | " &lt;&lt; game_board[0][1] &lt;&lt;" | " &lt;&lt;game_board[1][1] &lt;&lt; " | " &lt;&lt; game_board[2][1] &lt;&lt; " | "&lt;&lt;endl;
          cout &lt;&lt; " 3 | " &lt;&lt; game_board[0][2] &lt;&lt;" | " &lt;&lt;game_board[1][2] &lt;&lt; " | " &lt;&lt; game_board[2][2] &lt;&lt; " | \n"&lt;&lt;endl;
  
          //TESTING PURPOSES BE SURE TO REMOVE!
          current_player = 1;
  
          //Says which player is first
          cout &lt;&lt; "Player " &lt;&lt; current_player &lt;&lt; " is first!" &lt;&lt; endl;
  
          //Determines which player is first, and if so, which character to give to them.
          if(current_player == 1)
          {
              cp_char = "X";
          } else if(current_player == 2) 
          {
              cp_char = "Y";
          }
  
          bool valid_input = false;
  
          while(valid_input != true){
              cout &lt;&lt; "Where would you like to place your " &lt;&lt; cp_char &lt;&lt; " ? (X co-ordinates(top row))\n" ;
              cin &gt;&gt; x_coords;
              cout &lt;&lt; "Where would you like to place your " &lt;&lt; cp_char &lt;&lt; " ? (Y co-ordinates(side row))\n" ;
              cin &gt;&gt; y_coords;
  
              if((x_coords &lt;= 3) &amp;&amp; (y_coords &lt;=3))
              {
                  if(game_board[x_coords-1][y_coords-1] == "")
                  {
                      game_board[1][2] = "";
                      game_board[2][0] = "";
                      //Problem Here!
                      game_board[x_coords-1][y_coords-1] = cp_char;
                      break;
                      valid_input = true;
                  }
                  else
                  {
                      cout &lt;&lt; "Invalid Input! Somebody has already taken the slot!" &lt;&lt; endl;
                  }
              }
              else
              {
                  cout &lt;&lt; "Invalid input! Please enter a number from 1 to 3" &lt;&lt; endl;
              }
          }
          //End of Valid Input Loop
  
          //make sure to remove break; 
          // break;
      }
  
      system("pause");
      return 0;
  }
  </code></pre>
  
  <p>I haven't finished the game yet, but was at a loss as to why this is happening :s </p>
  
  <p>On another side note, Im also looking for a way to randomly decide whether player 1 or 2 goes first.</p>
  
  <p>Edit: I tried doing [3][3], as suggested but it still gives me an error. Ideas?</p>