2013-02-04, 06:37 PM
(This post was last modified: 2013-02-04, 07:20 PM by MariettaRC.)
This is almost embarrassing, but whatever.
I'm getting an incorrect value from this with the numbers I entered:
90 100 88 76 92 83 75 93 78 89
The answer I'm getting varies with the fiddling of the "total =- high - low;" line but none of them are correct.
I'm also getting rounded answers instead of exact answers (i.e. 95.00 when it should be 86.12), not sure what's going on there.
Objective: To insert 10 grades, remove the highest and lowest (why you would remove the highest grade, I have no idea) and calculate the average.
[MENTION=1102]Kalovale[/MENTION] The major I'm in focuses less on programming and more on concepts. :I /lateresponse
Code:
import java.util.Scanner;
public class InsertFinalGrade
{
public static void main(String[] args)
{
int[] c;
int grade;
int total = 0;
double finalGrade;
int high = 0;
int low = 100;
c = new int[10];
high = c[0]; //Gives the current "high" value to the first grade entered.
low = c[0]; //Gives the current "low" value to the first grade entered.
Scanner input = new Scanner (System.in);
System.out.println("Enter homework grades with spaces: ");
for (int counter = 0; counter < c.length; counter++) //array length = 10
{
grade = input.nextInt();
if (grade > high)
{
high = grade; //This grade is the highest grade if applied.
}
else if (grade < low)
{
low = grade; //This grade is the lowest grade if applied.
}
total += grade; //Add grades up.
}
total -= high + low; //ERROR IS PROBABLY ON THIS LINE.
finalGrade = total/8; //Divide total by the number of entered grades - low - high = 8 grades.
System.out.printf("Your final grade is %.2f", finalGrade); //Print final grade.
}
}I'm getting an incorrect value from this with the numbers I entered:
90 100 88 76 92 83 75 93 78 89
The answer I'm getting varies with the fiddling of the "total =- high - low;" line but none of them are correct.
I'm also getting rounded answers instead of exact answers (i.e. 95.00 when it should be 86.12), not sure what's going on there.
Objective: To insert 10 grades, remove the highest and lowest (why you would remove the highest grade, I have no idea) and calculate the average.
[MENTION=1102]Kalovale[/MENTION] The major I'm in focuses less on programming and more on concepts. :I /lateresponse

