Loop help



Okay, I'll try to explain this as clearly as possible.

I have a marks program that allows the user to input three marks, gain a
total and output a grade depending on what the mark was.
There are 4 different grades I have within an if statement:

- Distinction(70 or more)
- Merit (60 or more)
- Pass (40 or more)
or else it's a fail

I have a do while loop which prompts if the user wants to enter another
set of marks and that all works fine and catches invalid data.

When 'no' is selected, it takes you to a results table but this is where I
am having trouble.

I need the program to add up how many of each grade types there was
entered, the total of the number of mark sets entered and a percentage of
how many were a fail mark.

I'm having trouble assigning some sort of loop to count each grade type
and perform those calculations.

I will post the main segment of the code (without elements that aren't
causing problems such as variables and validation) which should hopefully
explain more of the above if I have commented it well:

(EasyIn is an input class I use to make input validation easier)
===============================================
// Start loop for data input

do
{

// Aquire the first mark

System.out.print("\n\nPlease enter the first mark (0-10) : ");
mark1 = EasyIn.getInt();


// Aquire the second mark
System.out.print("\n\nPlease enter the second mark (0-20) : ");
mark2 = EasyIn.getInt();


// Aquire the third mark
System.out.print("\n\nPlease enter the third mark (0-70) : ");
mark3 = EasyIn.getInt();

// Calculate the total marks to get the final score
score = mark1 + mark2 + mark3;


// Calculate the score to get grade

if (score >= 70) {
grade = "distinction";
}
else if (score >= 60) {
grade = "merit";
}
else if (score >= 40) {
grade = "pass";
}
else {
grade = "fail";
}

System.out.println("\n\n" scored " + score + " which is a "+ grade +
".\n\n");

// Prompt for Yes or No input

System.out.println("Do you wish to enter another set of marks?");

System.out.println("Please enter Y or N : ");
Yes_No = EasyIn.getChar();
}

// If input is "Yes", execute the above
while (Yes_No == 'Y' || Yes_No == 'y' );


// If user inputs "No", go to Results Breakdown
if (Yes_No == 'N' || Yes_No == 'n' )
{
System.out.println("\n\n\tResults Breakdown\n\n ");

System.out.println("\tFails :\t\t " ); System.out.println("\tPasses :
\t\t " );
System.out.println("\tMerits :\t\t " );
System.out.println("\tDistinctions :" );

System.out.println("\n\n Total graded:\n" );
System.out.println("\tPercentage failed: :\n" );
System.out.println("\tThe best program of the year award goes to: " + name
+ "\n"
+ "\twith a final mark of\n\n " );

}
}

==================================================

Please let me know if more info is needed.

If anyone could point me in the right direction, (as I am hopeless at
loops...) it would be very much appreciated.


.



Relevant Pages

  • Re: Calcluating Grades
    ... I am trying to calculate a persons grade, ... To calculate the grade code awarded for a given mark ... char getGrade{ ... you have a C99 compiler and when posting code on ...
    (comp.lang.c)
  • Re: GCSEs (again)
    ... >> The main problen with GCSEs over GCE 'O' Levels and CSEs is that there ... my rolling average would have exceeded the pass mark ... Therefore the 'A; grade becomes worhtless ...
    (uk.rec.motorcycles)
  • Re: Calcluating Grades
    ... I am trying to calculate a persons grade, ... To calculate the grade code awarded for a given mark ... Or that the function claims to return a char, ...
    (comp.lang.c)
  • Re: Calcluating Grades
    ... I am trying to calculate a persons grade, ... To calculate the grade code awarded for a given mark ... the correct direction. ...
    (comp.lang.c)
  • Re: Calcluating Grades
    ... I am trying to calculate a persons grade, ... To calculate the grade code awarded for a given mark ... between pointer and integer. ... the correct direction. ...
    (comp.lang.c)