Question: C Program Hello, i have this c program that asks the user to input grades and stops when the user enters -1. Then it has
C Program
Hello, i have this c program that asks the user to input grades and stops when the user enters -1. Then it has to find the average, total grades entered, lowest and highest grade. I already wrote the code. Can you please edit it for input restriction so they can not enter grades lower than 0 and higher than 100. Thank you!
#include
/**************************************************************************** * * * Function: main * * * * Purpose : Main entry point. * * * * History : Date Reason * * 00/00/00 Created * * * ****************************************************************************/
int main() { int grade, count, total = 0,lowestgrade=100,hightestgrade=0; count = 0; while (grade != -1) {
total += grade; count++; printf("Enter a grade between 1 and 100, enter -1 to stop the program: "); scanf("%d", &grade); if (grade !=-1 && grade < lowestgrade) { lowestgrade = grade; } if (grade > hightestgrade) { hightestgrade =grade; }
}
int average = (total+1) / (count-1); //total+1 because it counts -1 as a grade too,count-1 for the same reason. printf("The total number of grades entered is %d ", (count-1)); printf("The grade average is %d ", average); printf("The lowest grade is %d ", lowestgrade); printf("The hightest grade is %d ", hightestgrade); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
