value return function

Dec 2, 2014 at 1:01am
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.

Dec 2, 2014 at 1:03am
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 Dec 2, 2014 at 6:22pm
Dec 2, 2014 at 1:08am
Excuse me? @sunzhen11314
Last edited on Dec 2, 2014 at 1:08am
Dec 2, 2014 at 1:32am
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;
}
Dec 2, 2014 at 1:36am
would it remain the same if each score had a different weight
such as a = 10% b = 20% c = 30% d = 40%
Dec 2, 2014 at 1:40am
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 Dec 2, 2014 at 1:40am
Topic archived. No new replies allowed.