hey guys I have an assignment in programming in c which says :
" 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 "
I wrote a code but my problem is how to reject input like characters ..:
#include <stdio.h>
#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 > ", sentinel);
status = scanf ("%d", &score); // checking the validity of the input
max = score; // the initial maximum
min = score; // the initial minimum
while (score != sentinel) {
while (score < 0 || score > 100) // no negative or more than 100 score
{
printf ("The number is out of the range ; try again> ");
scanf ("%d", &score);
}
sum = sum + score;
i = i + 1;
printf (" Enter the score , %d to termenate > ", sentinel);
status = scanf ("%d", &score);
if (score > max && score < 100)
max = score;
if (score < min && score > 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;
}
I hope you can help me