I am using a while statement to count the total number of grades which works great, but my if and else statements to count how many A's, B's, etc...it seems the program is going through the While statement totally ignoring my if and else if statements.
I tried doing muliple while statements but that gives unpredictable results. It seems I am missing one or two lines.
Here is what I have at the moment.
Expand|Select|Wrap|Line Numbers
- // main(): application entry point
- public static void main(String[] args){
- // input stream
- Scanner stdin = new Scanner(System.in);
- // read a list of exam scores total them and categorize them A,B,C,D,F.
- // initializing int
- int inputsProcessed = 0;
- int A = 0;
- int B = 0;
- int C = 0;
- int D = 0;
- int F = 0;
- System.out.println("Enter a list of grades:");
- //get the first value
- double inputs = stdin.nextDouble();
- //add total number of grades entered.
- while (inputs >= 0){
- //processed another value
- ++inputsProcessed;
- //get next value
- inputs = stdin.nextDouble();
- }
- //process A's
- if (inputs >= 90){
- //add each occurence
- ++A;
- }
- //process B's
- else if (inputs >= 80){
- //add each occurence
- ++B;
- }
- //process C's
- else if (inputs >= 70){
- //add each occurence
- ++C;
- }
- //process D's
- else if (inputs >= 60){
- //add each occurence
- ++D;
- }
- //process F's
- else if (inputs >= 0){
- //add each occurence
- ++F;
- }
- //else {
- //System.out.println("Proper input was not input");
- System.out.println("Total number of grades:" + inputsProcessed);
- System.out.println("Number of A's = " + A );
- System.out.println("Number of B's = " + B );
- System.out.println("Number of C's = " + C );
- System.out.println("Number of D's = " + D );
- System.out.println("Number of F's = " + F );
- }
- }