title: Langtons Ant in C++ (console) - core dumped
body: <p>I wrote a simple Langtons Ant in C++ (console). But (dont really know why) I'm getting a core dumped every time I run my program:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;ctime&gt;
  #include &lt;cstdlib&gt;
  
  using namespace std;
  
  int main()
  {
      srand(time(NULL));
  
      bool endGame = false;
      enum compass {north, east, south, west};
      compass dir = north;
      int x = 0, y = 0;
      int n = 30, m = 30;
  
      int **board = new int*[n];
      for(int i = 0; i &lt;n; i++)
          board[i] = new int[m];
  
      for(int i=0; i&lt;n; i++)
          for(int j=0; j&lt;m; j++)
              board[i][j] = rand()%2;
  
      long count = 0;
      while(!endGame)
      {
          for(int i = 0; i &lt; n; i++)
          {
              for(int j = 0; j &lt; m; j++)
              {
                  //Print board
                  if(board[i][j] == 0)
                      cout &lt;&lt; '+';
                  else
                      cout &lt;&lt; '#';
              }
              cout &lt;&lt; endl;
          }
  
          //Ant
          if (board[x][y] == 0)
          {
              board[x][y] = 1;
              switch (dir){
              case north:
                  dir = east;
                  x = ((x+1)%m);
                  break;
              case east:
                  dir = south;
                  y = ((y-1) % n);
                  break;
              case south:
                  dir = west;
                  x = ((x-1) % m);
                  break;
              case west:
                  dir = north;
                  y = ((y+1) %n);
                  break;
              }
          }else
          {
              board[x][y] = 0;
              switch(dir){
              case north:
                  dir = west;
                  x = ((x-1) % m);
                  break;
              case west:
                  dir = south;
                  y = ((y-1) % n);
                  break;
              case south:
                  dir = east;
                  x = ((x+1)%m);
                  break;
              case east:
                  dir = north;
                  y = ((y+1) %n);
                  break;
              }
          }
          cout &lt;&lt; endl &lt;&lt; count &lt;&lt; endl;
          count++;
          cin.sync();
          cin.get();
      }
      cin.sync();
      cin.get();
      return 0;
  }
  </code></pre>
  
  <p>How can I get rid of this error?</p>