Please post the solution and the output. Please save the program with the name \
ID: 3856090 • Letter: P
Question
Please post the solution and the output. Please save the program with the name 'grade.c'. Write a program that will prompt the user to input ten student scores to an array. The score value is between 0 - 100. The program will display the smallest and greatest of those values. It also displays the average score. Please give a good name to a variable.
Output:
Please input student scores one at a time.
Student 1: -10
Try again!
Student 1: 10
Student 2: 110
Try again!
Student 2: 20
Student 3: 30 etc.
******final result******
The maximum score is ...
The minimum score is ...
The average score is ...
Explanation / Answer
#include<stdio.h>
int main() {
int student_score; //to store present student score
int minimum; //store minimum score
int maximum; //store maximum score
double average; //store average score
int i, total_score; //helping variable
minimum = 100; //initialize
maximum = 0;
total_score = 0;
printf("Please input student scores one at a time. ");
for (i = 0; i < 10; i++) {
printf("Student %d: ", i+1); //request data
scanf("%d",&student_score); //read data
if (student_score < 0 || student_score > 100) { //condition of failure
printf("Try again ");
i--;
}
else {
if (student_score > maximum) //chk max
maximum = student_score;
if (student_score < minimum) //chk min
minimum = student_score;
total_score += student_score; //calulate total marks
}
}
average = (double)total_score/10; //calculate avg
/* print resuls*/
printf("******final result****** ");
printf("The maximum score is %d ", maximum);
printf("The minimum score is %d ", minimum);
printf("The average score is %f s", average);
}
Let me know if you like the code. Also point out if I have missed anything...
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.