Loop help
- From: "Yuriy_Ivanov" <phantom_enigma@xxxxxxxxxxxxxxxxx>
- Date: Tue, 27 Dec 2005 13:37:08 -0500
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.
.
- Follow-Ups:
- Re: Loop help
- From: Mark Thomas
- Re: Loop help
- Prev by Date: frustrating arithmetic
- Next by Date: Re: read variable from url into html
- Previous by thread: frustrating arithmetic
- Next by thread: Re: Loop help
- Index(es):
Relevant Pages
|
|