title: Temperature Converter Challenge
body: <p>I was doing a coding challenge for a website, the premise was:</p>
  
  <blockquote>
    <p>In this challenge, write a program that takes in three arguments, a start temperature (in 
    Celsius), an end temperature (in Celsius) and a step size. Print out a table that goes from > the start temperature to the end temperature, in steps of the step size; you do not 
    actually need to print the final end temperature if the step size does not exactly match. 
    You should perform input validation: do not accept start temperatures less than a lower 
    limit (which your code should specify as a constant) or higher than an upper limit (which 
    your code should also specify). You should not allow a step size greater than the 
    difference in temperatures. (This exercise was based on a problem from C Programming 
    Language).</p>
  </blockquote>
  
  <p>I got the same results as the solution did, but I'm curios as to why their solution is more efficient (I'd presume it is). Anyone able to explain it to me? Their solution is first followed by mine.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  #define LOWER_LIMIT 0
  #define HIGHER_LIMIT 50000
  
  int main(void) {
      double fahr, cel;
      int limit_low = -1;
      int limit_high = -1;
      int step = -1;
      int max_step_size = 0;
  
      /* Read in lower, higher limit and step */
      while(limit_low &lt; (int) LOWER_LIMIT) {
         printf("Please give in a lower limit, limit &gt;= %d: ", (int) LOWER_LIMIT);
         scanf("%d", &amp;limit_low);
      }
  while((limit_high &lt;= limit_low) || (limit_high &gt; (int) HIGHER_LIMIT)) {
      printf("Please give in a higher limit, %d &lt; limit &lt;= %d: ", limit_low, (int) HIGHER_LIMIT);
      scanf("%d", &amp;limit_high);
  }
  max_step_size = limit_high - limit_low;
  while((step &lt;= 0) || (step &gt; max_step_size)) {
      printf("Please give in a step, 0 &lt; step &gt;= %d: ", max_step_size);
      scanf("%d", &amp;step);
  }
  
  /* Initialise Celsius-Variable */
  cel = limit_low;
  
  /* Print the Table */
  printf("\nCelsius\t\tFahrenheit");
  printf("\n-------\t\t----------\n");
  while(cel &lt;= limit_high) {
      fahr = (9.0 * cel) / 5.0 + 32.0;
      printf("%f\t%f\n", cel, fahr);
          cel += step;
      }
      printf("\n");
  
      return 0;
  }
  </code></pre>
  
  <p>My solution:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  #define LOW 0
  #define HIGH 50000
  
  
  int main(void)
  {
  int lower, higher, step, max_step;
  float cel, fahren;
  
  printf("\nPlease enter a lower limit, limit &gt;= 0: ");
  scanf("%d", &amp;lower);
  
  if (lower &lt; LOW)
  {
      printf("\nERROR: Lower limit must be &gt;= 0.");
      exit(1);
  }
  
  
  printf("\nPlease enter a upper limit, limit &lt;= 50000: ");
  scanf("%d", &amp;higher);
  
  if (higher &gt; HIGH)
  {
      printf("\nERROR: Upper limit must be &lt;= 50,000.");
      exit(1);
  }
  
  printf("\nPlease enter an increment amount, 0 &lt; step &lt;= 10: ");
  scanf("%d", &amp;step);
  
  max_step = higher - lower;
  
  if (step &gt; max_step)
  {
      printf("\nERROR: Step size cannot exceed difference between higher and lower limit.");
      exit(1);
  }
  
  printf("Celsuis \tFahrenheit\n");
  printf("------- \t-----------\n\n");
  
  cel = (float)lower;
  
  while (cel &lt; higher)
  {
      fahren = cel * 9/5 + 32;
      printf("%f \t%f\n", cel, fahren);
      cel = cel + step;
  }
  
  return 0;
  </code></pre>
  
  <p>}</p>