Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I wrote this code here and it need some fixing please, 1- first I need to limit

ID: 3531725 • Letter: I

Question

I wrote this code here and it need some fixing please,


1- first I need to limit the users input soEach test score is only an integer greater than or equal to 0.so I want the user to get an error when they inter a negative number.


2- in my code the user can only terminate the list of scores by entering -1. I want it to work with any negative number not just -1.


here is my code and the original question so that you could understand it better.


Question))Write a program that will prompt the user to enter a list of test scores and then print the highest score, the lowest score and the average score for the list entered. Each test score is an integer greater than or equal to 0. The user will terminate the list of scores by entering a negative number.

Design constraints

Explanation / Answer

#include<stdio.h>


intmain()


{

intcounter =0;//initialize counter

inttotal =0;//initialize total

intgrade, min, max;

min=-1;//set min to -1 outside while loop

max=-1;//set max to -1 outside while loop

//prompt user to enter first score

printf(" enter test scores (-1 to end): ");

while( grade >-1)//set condition to exit while loop on any negative number

{

scanf("%d", &grade);

//condition for minimum number in list

if(grade - min <0)

min = grade;

//condition for maximum number in list

if(grade - max >0)

max = grade;

total += grade;//add up all the numbers in list

counter++;//count number of iterations in loop

}



//error checking; condition not to divide by zero else prompt user with message

if(counter !=0)

printf(" Class average is %.2f ", (float) total / counter);//print average

else

printf("You have not entered valid input");

printf("Lowest score is %d and highest score is %d ", min, max);//print min and max values

return0;//successful termination


}

since now we take all user input in while loop user cannot input negative number as test score since that will terminate the loop