title: Using clock() to take a time stamp (Visual Studio 2010, C/C++)
body: <p>Ok, so I am trying to implement the Collatz problem in C, and record/print the time it takes for the while loop to execute. I am supposed to report both the number of "ticks" and the time in seconds. However, I am getting some seemingly simple errors from my code but for whatever reason, I am not sure how to correct them.</p>
  
  <p>This is my code</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;time.h&gt;
  
  void main() {
      int n, c = 0;
      printf("Please enter an integer...\n");
      scanf("%d", &amp;n);
      clock_t start;   /* Line 8 */
      clock_t finish;  /* Line 9 */
  
      start = clock();
      while (n != 1) {
          if (n%2 == 0)
              n = n/2;
          else
              n = (3*n)+1;
          c++;
          printf("n=%d\n", n);
      }
      finish = clock() - start;
      double interval = finish / (double)CLOCKS_PER_SEC; 
  
          printf("%d iterations\n", c);
      printf("%f clock cycles", finish); 
      printf("%f seconds elapsed", interval);
  }
  </code></pre>
  
  <p>These are the errors Visual Studio is reporting</p>
  
  <p><strong>Line 8 and 9 Errors</strong></p>
  
  <p>'clock_t' : illegal use of this type as an expression</p>
  
  <p>syntax error : missing ';' before identifier 'start'</p>
  
  <p>'start' : undeclared identifier </p>
  
  <p>I am also getting an 'undeclared identifier' error for all lines in which 'start' or 'finish' show up</p>