0
public static void Main (string[] args)
   {

      int row;
      int column;
      int[,] game;
      game = new int[3, 3] { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } };

Console.WriteLine("Player 1's turn.");
      Console.Write("Enter row [1, 2 or 3]: ");
      row = Convert.ToInt32(Console.ReadLine());
      Console.Write("Enter column [1, 2 or 3]: ");
      column = Convert.ToInt32(Console.ReadLine());
      if (game[row,column] == 1 || game[row,column] == 2)
      {
         Console.WriteLine("Sorry that square is unavailable.  Please choose another one.");
         Console.Write("Enter row [1, 2 or 3]: ");
         row = Convert.ToInt32(Console.ReadLine());
         Console.Write("Enter column [1, 2 or 3]: ");
         column = Convert.ToInt32(Console.ReadLine());
      }
      else
      {
         game[--row, --column] = 1;
      }

that's the code, and I keep getting the error: Unhandled exception: System.IndexOutOfRangeException: Index was outside the bounds of the array.

There is something wrong it says with the IF statement. Any ideas?

2
Contributors
1
Reply
15
Views
3 Years
Discussion Span
Last Post by Momerath
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.