title: Input only number C programming
body: <p>currently i am doing a program to get the input (0 to 50) from the user.
  If the number is out of the range then the number will not be counted.
  After that, i will calculate and get the average, maximum and minimum for those
  inputs. I facing a problem when the user input character. The program will crack. I wonder how can i solve this problem? Thanks in advance.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;conio.h&gt;
  #include &lt;stdlib.h&gt;
  
  using namespace std;
  
  int main()
  {
  int i=1 , j=1,skor;             //variable untuk jumlah ujian
  float total = 0, average;       //variable untuk skor ujian, jumlah dan purata
  int min=99999;                  //variable untuk min
  int max=0;                  //variable untuk max
  
  printf("*******************************************************************************\n");
  printf("*                    Enter test scores,-1 to exit                              \n");
  printf("*******************************************************************************\n");
  printf("*                                                                              \n");
  //masukkan data skor dan perhitungan jumlah keseluruhan skor
  while (skor != -1)
  {
      printf("* Scores[%d] (0-50) : ", i);
      scanf("%d", &amp;skor);
      if(skor&gt;-1&amp;&amp;skor&lt;51)
      {
          total += skor;
          j++;
      }
      if(skor&gt;max&amp;&amp;skor&lt;51&amp;&amp;skor!=-1)
      {
          max=skor;
      }
      if(skor&lt;min&amp;&amp;skor&gt;=0&amp;&amp;skor!=-1)
      {
          min=skor;
      }
      i++;
  }
  j=j-1;
  //pengiraan purata
  average = total / j;
  //printf("\nJumlah = %.2f\n", Jumlah);
  //printf("\nj = %d\n", j);
  printf("*                                                                              \n");
  printf("*******************************************************************************\n");
  printf("* \n* Average marks = %.2f                                 \n", average);
  printf("*                                                                              \n");
  printf("*******************************************************************************\n");
  //pemaparan nilai min dan max
  printf("*                                                                              \n");
  printf("* MIN:%d \n", min);
  printf("* MAX:%d \n", max);
  printf("*                                                                              \n");
  printf("*******************************************************************************\n");
  getch();
  return 0;
  }
  </code></pre>
  
  <p>I want to limit that the input is only for integer value and not allow the user to input a character so that the program will not crack.</p>