3. Write a program to calculate a student\'s grade based on three test scores, u
ID: 3796431 • Letter: 3
Question
3. Write a program to calculate a student's grade based on three test scores, using the guidelines below: Write a function readScores and call it three times to read three test scores (between 0 and 100), using data type float for the scores. .Call a function calculateGrade to determine the student's grade from the three test scores using the algorithm below. The function calculateGrade receives the three scores and returns the grade as a character. Implement the algorithm using nested statements within a given range rather than merely simple if statements. The grade is not printed from this function. These are the guidelines: o If the average score is 90% or more, the grade is A. o If the average score is 70% or more and less than 90%, check the third score. If the third score is more than 90%, the grade is A; otherwise the grade is B. o If the average score is 50% or more and less than 70%, check the average of the second and third scores. If the average of the two is greater than 70%, the grade is C; otherwise the grade is D. o If the average score is less than 50% then the grade is F Print the student's grade from function main (or if you prefer, from a printResults function). Test with the following sets of scores: Test 3 a. Test 1 score: 74 Test 2 score: 82 Score: 92 b. Test 1 score: 62 Test 2 score: 84 Test 3 score: 73 c. Test 1 score: 52 Test 2 score: 64 Test 3 score: 85 d. Test 1 score: 54 Test 2 score: 62 Test 3 Score: 61Explanation / Answer
#include <stdio.h>
float readScores(int i) {
float score;
printf("Enter test %d score : ",i);
scanf("%f",&score);
return score;
}
char calculateGrade(float score1, float score2, float score3) {
float average;
float averof2sub;
char grade;
average = (score1 + score2 + score3) / 3;
averof2sub = (score2 + score3) / 2;
if(average >= 90) {
grade = 'A';
} else if(average >=70 && average < 90 && score3 >= 90) {
grade = 'A';
} else if(average >=70 && average < 90 && score3 < 90) {
grade = 'B';
} else if(average >= 50 && average < 70 && averof2sub > 70) {
grade = 'C';
} else if(average >= 50 && average < 70 && averof2sub <= 70) {
grade = 'D';
} else if(average < 50) {
grade = 'F';
}
return grade;
}
int main() {
int score1, score2, score3;
score1 = readScores(1);
score2 = readScores(2);
score3 = readScores(3);
printf("Grade is %c", calculateGrade(score1, score2, score3));
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.