title: Computing Minimum, Maximum, and Average Test Score Input Validation
body: <p>hey guys I have an assignment in programming in c which says :</p>
  
  <p>"  Write a C program that inputs a list of integer test scores
  between 0 and 100, and computes the maximum score, the minimum
  score, and the average score. Use -1, as a sentinel, to mark the end of the
  input. Reject any test score outside the range 0 to 100. Your program
  should also detect and reject faulty input, such as letters and characters.
  You should have a function that reads and validates an input test score
  and rejects invalid and faulty input. Here is a sample run "</p>
  
  <p>I wrote a code but my problem is how to reject input like characters ..:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #define sentinel -1     // to end the program
  
  int main ()
  {
      int status, score, sum, i, max, min;
      double avrg;
      i = 0;          /* the counter */
      sum = 0;            // the total scores
      printf (" Enter the score , %d to termenate &gt; ", sentinel);
      status = scanf ("%d", &amp;score);  // checking the validity of the input
  
      max = score;        // the initial maximum
      min = score;        // the initial minimum
  
      while (score != sentinel) {
  
          while (score &lt; 0 || score &gt; 100)    // no negative or more than 100 score
  
          {
              printf ("The number is out of the range ; try again&gt; ");
              scanf ("%d", &amp;score);
          }
  
          sum = sum + score;
          i = i + 1;
          printf (" Enter the score , %d to termenate &gt; ", sentinel);
          status = scanf ("%d", &amp;score);
          if (score &gt; max &amp;&amp; score &lt; 100)
              max = score;
          if (score &lt; min &amp;&amp; score &gt; 0)
              min = score;
      }
  
      if (i != 0) {
          avrg = (double) sum / i;    // the sum of scores over the number of scores
          printf (" The avarage is : \n %.2f ", avrg);
          printf ("\n");
          printf (" Maximum score is : \n %d", max);
          printf ("\n");
          printf ("Minmum score is : \n %d", min);
      } else          // when the user ends the program without entering any value
      {
          printf ("You didn't enter any score");
      }
  
      return 0;
  }
  </code></pre>
  
  <p>I hope you can help me </p>