# Thread: Problem in an exercise

1. Member
Join Date
Nov 2010
Posts
2
Rep Power
0

## Problem in an exercise

So folks. I am on a course trying to learn Java. It scares me because I still don't totally understand all the concepts, and making a driver file is beyond me as yet but I have a question. We have an exercise to

Design and implement a marks grading program. The program should prompt the user to enter a sequence of integer marks in the range 0 .. 100. The sequence will be terminated by a sentinel value -1.

Marks will be graded according to the scheme:
Mark Range 0 .. 39 40 .. 59 60 .. 79 80 .. 100

The program should display the number of grade A's, the number of grade B's, the number of grade C's, the number of grade D's and the overall average (as an integer value).

I tried to have a go at it, but unfortunately, my code just gets stuck and I can't figure it out. Can someone help me? Enter any number and it won't prompt you to enter another number.. It just sits there

Java Code:
import java.util.Scanner;

public class Exercise5
{
public static void main(String[]args)
{
int iNumber;
int iInputs =0;
double dAverage =0.0;
int iTotal =0;
int iA = 0;
int iB = 0;
int iC = 0;
int iD = 0;

Scanner input= new Scanner(System.in);
iNumber=input.nextInt();

//public void Determine(){}
for(iNumber =0; iNumber >=0; iInputs++)
{

if(iNumber > 100)
System.out.println("Number cannot be greater than 100, please try again \n");

if(iNumber >=80 && iNumber <=100)
iA++;
iInputs++;

if(iNumber >=60 && iNumber <=79)
iB++;
iInputs++;

if(iNumber >=40 && iNumber <=59)
iC++;
iInputs++;

if(iNumber >=0 && iNumber <=39)
iD++;
iInputs++;

}

dAverage = iTotal / iInputs;

System.out.printf("Number of inputs was:%d\n" +
"Number of A's:%d\n" +
"Number of B's:%d\n" +
"Number of C's:%d\n" +
"Number of D's:%d\n" +
"Average of Grade Score was %d\n",iInputs, iTotal, iA, iB, iC, iD, dAverage);

}

}
Last edited by Honest989; 11-10-2010 at 10:04 PM.

2. Member
Join Date
Nov 2010
Posts
2
Rep Power
0
OK, an update is that I've sorted that so it now functions correctly but now it's not adding to iTotal(mainly because I haven't done anything with it) but how would I get it to evaluate and add what is put in to the total?

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•