title: How to stop programme from reading if -1 is entered, and calculate average accordingly
body: <p>I'm a beginner in C, and my task is to:
  Write a program that reads in an array of up to 10 integers representing peoples ages in years and calculates and prints the maximum age and the minimum age and the average age. Your program should stop reading when either the 10th number is entered or the user enters -1. If the user enters any other negative number or a value above 150, they should be warned and prompted again for a valid age.</p>
  
  <p>My code can find the maximum and minimum numbers and calculate the average, as well as ensuring the value is between 0 to 150. However I can't get the programme to stop if -1 is entered. My average, minimum, and maximum also just consider that 10 values are entered, so I need help in counting the amount of values entered by the user before (/if) -1 is entered, so they can be accurate.</p>
  
  <pre><code>int ages[10];
  int i, j;
  double sum=0;
  
  for (i=0; i&lt;10; i++){
      printf("Enter number %d: ",i+1);
      scanf("%d", &amp;ages[i]);
      if (ages[i]&lt;-2 || ages[i]&gt;150){
          printf("Invalid number, enter again: ");
              scanf("%d",&amp;ages[i]);
          while (ages[i]==-1){
              break;
          }
      }
  }
  
  for (i=0; i&lt;10; i++){
      sum=sum+ages[i];
  }
  printf("Average: %f \n", (sum/10));
  int min=ages[0];
  int max=ages[0];
  
  for (j=0; j&lt;10;j++){
      if (ages[j]&gt;max){
         max=ages[j];
      }
      else if (ages[j]&lt;min){
          min=ages[j];
      }
  }
  printf("Minimum: %d. Maximum: %d. \n", min, max);
  </code></pre>