value return function

How do you write a write a value return function computes the average of four scores and returns the average? That score must then be sent to a function to determine the letter grade.

1
2
3
4
5
char grade(int score)
{
 if(90<score<100) return A;
 else if(80<score<90) return B;
}

Like this format to determine the letter grade of the score.
Last edited on
Excuse me? @sunzhen11314
Last edited on
1
2
3
4
double compute_average_of_four_numbers(double a, double b, double c, double d)
{
    return (a+b+c+d)/4.0;
}
would it remain the same if each score had a different weight
such as a = 10% b = 20% c = 30% d = 40%
It's not as simple, but it is still very simple. Just multiply each score by its weight, and add everything up. For example with your numbers, you could use the expression 0.10*a + 0.20*b + 0.30*c + 0.40*d
Last edited on
Topic archived. No new replies allowed.