In the language C ... code for the sample output: Enter the midterm1 grade: -1 I
ID: 641393 • Letter: I
Question
In the language C ... code for the sample output:
Enter the midterm1 grade: -1
Invalid grade enter the grade again: 222
Invalid grade enter the grade again: 0
Enter the midterm2 grade: -3
Invalid grade enter the grade again: 88
Enter the final grade: 45
Highest grade for the student is 88 in midterm2
Lowest grade for the student is 0 in midterm 1
Students total is 44.33 and overall grade in the course is F
Do you want to continue (enter 1 to continue and 0 to exit): 0 ***mainly need help on this part***
Explanation / Answer
#include <stdio.h>
char getGrade(double avg){
if(avg >= 90){
return 'A';
}
else if(avg >= 80 && avg < 90){
return 'B';
}
else if(avg >= 70 && avg < 80){
return 'C';
}
else if(avg >= 60 && avg < 70){
return 'D';
}
else if(avg >= 50 && avg < 60){
return 'E';
}
else{
return 'F';
}
}
double getAverage(int g1, int g2, int g3){
return (g1 + g2 + g3) / 3.0;
}
int main(){
int g1, g2, final;
int max, min;
double avg;
int option;
do{
printf("Enter the midterm1 grade: ");
scanf("%d", &g1);
while(g1 < 0 || g1 > 100){
printf("Invalid grade enter the grade again: ");
scanf("%d", &g1);
}
printf("Enter the midterm1 grade: ");
scanf("%d", &g2);
while(g2 < 0 || g2 > 100){
printf("Invalid grade enter the grade again: ");
scanf("%d", &g2);
}
printf("Enter the Final grade: ");
scanf("%d", &final);
while(final < 0 || final > 100){
printf("Invalid grade enter the grade again: ");
scanf("%d", &final);
}
double avg = getAverage(g1, g2, final);
char grade = getGrade(avg);
printf("Student Average is %.2lf and overall grade in the course is %c ", avg, grade);
printf("Do you want to continue (enter 1 to continue and 0 to exit): ");
scanf("%d", &option);
}while(option == 1);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.