Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Java - Calculating an average with two removed values.
#4
[SPOILER="I don't have a Java compiler installed so I did a test in C, success"]
Code:
#include <stdio.h>

int main()
{
    int c[10] = {90, 100, 88, 76, 92, 83, 75, 93, 78, 89};
    int total = 0;
    double finalGrade;
    int high = c[0];
    int low = c[0];

    for (int i = 0; i < 10; i++)
    {
        int grade = c[i];
        if (grade > high)
            high = grade;
        else if (grade < low)
            low = grade;
        total += grade;
    }

    total -= high + low;
    
    finalGrade = total/8.0;

    printf("total %d\n", total);
    printf("finalGrade %.2f\n", finalGrade);
    printf("high %d\n", high);
    printf("low %d\n", low);

    return 0;
}

//output:
//total 689
//finalGrade 86.12
//high 100
//low 75
Reply


Messages In This Thread
Java - Calculating an average with two removed values. - by Dusk - 2013-02-04, 07:11 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)