title: How to check if a number is closer to a specific number?
body: <blockquote>
    <p>write a program that repeatedly asks a user to enter numbers between 0
    to 100, until the user enters a value outside that range. Then output
    the number closest to 50.</p>
    
    <p>For example:</p>
    
    <p>Enter a number: 91.3<br>
     Enter a number: 64.4<br>
     Enter a number: 38.12<br>
     Enter a number: 46.9<br>
     Enter a number: 99.45<br>
     Enter a number: 103.   </p>
    
    <p>The number closest to 50 is 46.900000</p>
  </blockquote>
  
  <p>I have only learnt do,while,for loops, if and else if selection statements. </p>
  
  <p>I understand I would need an if statement that checks the difference between each number with 50, the smaller the difference, the closer the number to 50. I included stdlib.h because I figured I would need to  take the absolute value of the difference to avoid negative number.
  Yet I do not know how to incorporate this thought into the codes. How should the code be written?</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  
  int main (void)
  {
    float num;
    printf("Enter a number:");
    scanf("%f",&amp;num);
  
    while (num&gt;=0 &amp;&amp; num&lt;=100)
    {
      printf("Enter a number:");
      scanf("%f",&amp;num);
      //I think I would need an if statement here to check the difference
    }
    printf("\nThe closest is %.2f",/*I think I would need a new variable here.*/ );
    return 0;
  }
  </code></pre>