/* * Prog_Practice_W5.c * * Created on: Jan 14, 2022 * Author: johnsontimoj */ //////////////////////////////////// // // Program to calculate the letter grade of a student // based on 3 scores // // inputs: student ID, 3 scores // outputs: printed letter grade //////////////////////////////////// #include // function declarations (prototypes) int get_score(int std_num, int cnt); float calc_ave(int s1, int s2, int s3); void print_grade(int std_num, float score); char calc_grade(float score); int main(void){ setbuf(stdout, NULL); // fix code composer issue // splash printf("\nWelcome to Dr. Johnson's Letter Grade calculation program\n"); // local variables int student_ID; int score_1; int score_2; int score_3; float average; while(1){ // get student ID printf("\nPlease enter the students ID number:"); scanf("%i", &student_ID); // get scores score_1 = get_score(student_ID, 1); score_2 = get_score(student_ID, 2); score_3 = get_score(student_ID, 3); // calculate average average = calc_ave(score_1, score_2, score_3); // print the letter grade print_grade(student_ID, average); }// end while return 0; }// end main int get_score(int std_num, int cnt){ // function to get a single score for a student int score; printf("Please enter score # %i for student # %i: ", cnt, std_num); scanf("%i", &score); return score; }// end get_score float calc_ave(int s1, int s2, int s3){ // function to calculate the normal average of 3 numbers return (s1 + s2 + s3)/3.0 ; // forcing float division }// end calc_score void print_grade(int std_num, float score){ // function to print grades // based on scores // uses calc_grade() char grade; // calc grade grade = calc_grade(score); // print the grade printf("Student # %i has a grade of: %c \n", std_num, grade); return; }// end print_grade char calc_grade(float score){ // function to calculate the letter grade // based on a numeric value // using standard grade mapping char grade; // calculate grade if(score >= 90) grade = 'A'; else if(score >= 80) grade = 'B'; else if(score >= 70) grade = 'C'; else if(score >= 60) grade = 'D'; else grade = 'F'; return grade; }// end calc_grade