#include <stdio.h>

/*
 * Terry Harvey cisc105 section 10
 *
 * This program takes three exam grades, computes the average, and
 * gives a letter grade for the average. Even though we could have
 * done all this in the main() function, we put parts into other
 * functions to practice functional decomposition.
 */

double showAverage(double exam1, double exam2, double exam3);
void showLetterGrade(double average);

int main(){

    double test1, test2, test3;
    double avg;

    printf("Enter three test grades: ");
    scanf("%lf%lf%lf", &test1, &test2, &test3);
    printf("three grades are: %lf %lf %lf\n", test1, test2, test3);

    avg = showAverage(test1, test2, test3);

    showLetterGrade(avg);

    return 0;
}

/*
 * Takes three exam grade parameters, calculates average, prints it
 * and returns it.
 */
double showAverage(double exam1, double exam2, double exam3){
    double avg;
    avg = (exam1 + exam2 + exam3) / 3;
    printf("avg is now %lf\n", avg);

    return avg; //send avg value back to calling function
}

/*
 * Takes the average as a parameter and displays matching letter
 * grade.
 */
void showLetterGrade(double average){ 

//    if (average >= 90)
//        printf("A");
//    else if (average >= 80)
//        printf("B");
//    else if (average >= 70)
//        printf("C");
//    else if (average >= 60)
//        printf("D");
//    else if (average >= 0)
//        printf("F");

    switch( (int)average /10){
    case 10: printf("A"); break;
    case 9:  printf("A"); break;
    case 8:  printf("B"); break;
    case 7:  printf("C"); break;
    case 6:  printf("D"); break;
    case 5:  printf("F"); break;
    default: printf("F");
    }

    printf("\n");
    return;
}
