Results 1 to 2 of 2
  1. #1
    Honest989 is offline Member
    Join Date
    Nov 2010
    Posts
    2
    Rep Power
    0

    Default 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
    Grade D C B A

    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;
    
           System.out.println("Input next grade:\n");
           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" +
                      "Total of Grades 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. #2
    Honest989 is offline Member
    Join Date
    Nov 2010
    Posts
    2
    Rep Power
    0

    Default

    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?

Similar Threads

  1. Have I done this exercise right?
    By ccie007 in forum New To Java
    Replies: 7
    Last Post: 09-28-2010, 06:54 PM
  2. Exercise problem, how was this output achieved?
    By bs3ac in forum New To Java
    Replies: 8
    Last Post: 08-06-2010, 03:38 PM
  3. Exercise for java 3d
    By armiri in forum Java Software
    Replies: 3
    Last Post: 05-14-2010, 12:13 AM
  4. I/O exercise
    By Feldom in forum New To Java
    Replies: 1
    Last Post: 10-28-2007, 05:48 PM
  5. help with exercise
    By e_as're in forum New To Java
    Replies: 3
    Last Post: 09-25-2007, 11:14 AM

Posting Permissions

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