Given a user inputted list of numbers (input -1 to stop), determine the high, low, and average values of the list.
I'm new to C, this is my code so far:
#include <stdio.h>
int main()
{
int i, numgrades, sum, high, low;
float ave;
numgrades = 0, sum = 0, high = 0, low = 0;
printf("Enter grade: ");
scanf("%d", &i);
while (i != -1) {
if (high<i)
high = i;
else if (low>=i)
low = i;
if ((i>=0)&&(i<=100)) {
printf("Enter grade: ");
scanf("%d", &i);
numgrades = numgrades + 1;
sum = sum + i;
}
else
printf("The entered value is not in the range of 0-100.\n");
printf("Enter grade: ");
scanf("%d", &i);
numgrades = numgrades + 1;
sum = sum + i + 1;
}
ave = (float)sum / numgrades;
if (i == -1) {
printf("%d grades entered, high = %d, low = %d, ave = %.1f\n", numgrades, high, low, ave);
}
return(0);
}
I'm new to C, this is my code so far:
#include <stdio.h>
int main()
{
int i, numgrades, sum, high, low;
float ave;
numgrades = 0, sum = 0, high = 0, low = 0;
printf("Enter grade: ");
scanf("%d", &i);
while (i != -1) {
if (high<i)
high = i;
else if (low>=i)
low = i;
if ((i>=0)&&(i<=100)) {
printf("Enter grade: ");
scanf("%d", &i);
numgrades = numgrades + 1;
sum = sum + i;
}
else
printf("The entered value is not in the range of 0-100.\n");
printf("Enter grade: ");
scanf("%d", &i);
numgrades = numgrades + 1;
sum = sum + i + 1;
}
ave = (float)sum / numgrades;
if (i == -1) {
printf("%d grades entered, high = %d, low = %d, ave = %.1f\n", numgrades, high, low, ave);
}
return(0);
}