hey, i started a uni degree last month in computing.
ive found getting to grips with the programing side of it a little difficult though. basically im trying to write a program to do this.
read a list of exam scores from the keyboard and to output the total number of grades in each of the following categories:
80-100 = Distinction;
50-79 = Pass
0-49 = Fail.
the program then needs to allow the user to end the loop by inputting a negative score.
For example if the input is:
98 87 86 85 85 78 73 72 72 72 70 66 63 49 -1
The output should show
Total number of grades = 14
Number of Distinctions = 5
Number of Passes = 8
Number of Fails = 1
i can get the program to read the score, and save it in a varible. but when i try adding a loop it no longer records them into the varible and prints them out?
Heres my code so far
import java.util.*;
public class grades
{
public static void main(String[] args)
{
int grade, totalgrades, avdistinction, avpass, avfail;
int distinction= 0;
int pass = 0;
int fail = 0;
int stop = -1;
System.out.println("Please Enter Students Grade");
Scanner keyboard = new Scanner(System.in);
do
grade = keyboard.nextInt();
while (grade > stop);
{
if ((grade >=80) && (grade <=100))
distinction = distinction +1;
else
if ((grade >50) && (grade <=79))
pass = pass +1;
else
if ((grade >0) && (grade <50 ))
fail = fail +1;
System.out.println("Distinctions = " + distinction);
System.out.println("Passes = " + pass);
System.out.println("Fails = " + fail);
totalgrades = (distinction + pass + fail);
System.out.println("Total Number Of Grades = " + totalgrades);
}
}
}
any help would be very appreciated, ive been doing this for 5 hours plus now lol. just need to now where im going wrong. thanks
|