title: Infinite loop (C)
body: <p>The problem this this code is in the while loop under beetleSimulation, it goes on forever instead of exiting when x/yCount goes out of the bounds. x and y go on much further than 20, can anyone help me out to why?</p>
  
  <pre><code>      #include &lt;stdio.h&gt;
          #include &lt;stdlib.h&gt;
          #include &lt;math.h&gt;
          #define PI 3.14159265
          void beetleSimulation(int, int)
  
  ;
  
  
      int main ( int argc, char *argv[] )
      {
          if ( argc != 2 ) // argc should be 2 for correct execution 
          {
              // If the number of arguments is not 2
              printf("%d", argc);
          }
          else 
          {
             //run the bee
  </code></pre>
  
  <p>tle simulation
              beetleSimulation(argv[1], argv[2] );
              }
          }</p>
  
  <pre><code>void beetleSimulation(int size, int iterations){
      int i;
      int xCount = 0;
      int yCount = 0;
      int timeCount = 0;
      int overallCount = 0;
      for(i=0; i &lt; 10; i++){
          while(xCount &lt; 20 || xCount &gt; -20 || yCount &lt;20 || yCount &gt;-20){
              timeCount += 1;
              int degree = rand() % 360;
              double radian = degree / 180 * PI;
              xCount += sin(radian);
              yCount += cos(radian);
          }
  
          //when beetle has died, add time it took to overall count, then go through for loop again
          overallCount += timeCount;
      }
      //calculate average time
      double averageTime = overallCount/iterations;
      printf("%d",averageTime);
  }
  </code></pre>