#include <stdio.h>
#include <string.h>
const char* toLetterGrade(double score) {
// Define scores and grades
double scores[] = {95.0, 90.0, 85.0, 80.0, 75.0, 70.0, 65.0, 60.0};
const char* grades[] = {"A+", "A", "B+", "B", "C+", "C", "D+", "D"};
// Find the length of the scores array
int scores_size = sizeof(scores) / sizeof(scores[0]);
// Iterate through scores and find the grade
for (int i = 0; i < scores_size; i++) {
if (score >= scores[i]) {
return grades[i];
}
}
return "F"; // Default grade if none of the scores match
}
int main() {
// Test the program with individual scores
printf("%s\n", toLetterGrade(95)); // A+
printf("%s\n", toLetterGrade(90)); // A
printf("%s\n", toLetterGrade(80)); // B
printf("%s\n", toLetterGrade(60)); // D
printf("%s\n", toLetterGrade(50)); // F
return 0;
}
/*
run:
A+
A
B
D
F
*/