problem with displaying result..
hello there.. I have this simple application that it supposed to show the average of the numbers that you enter.. but I seem to have a mistake with the calculations.. i think it has to do with typecasting or something. The average is just not correct!! Any help would appreciated. Thanks.
the code:
Quote:
import java.util.*;
public class ex {
public static void main(String[] args) {
double sum = 0;
int counter = 0;
double average = 0;
double input = 0;
do {
System.out.print("ENTER A GRADE (OR ENTER -1 TO EXIT) ");
input = new Scanner(System.in).nextDouble();
sum+=input;
counter++;
average= sum / (float)counter;
}
while (input != -1);
System.out.println("\nThe average is " + average );
}
}