User User name Password  
   
Sunday 3.8.2025 / 04:27
Search AfterDawn Forums:        In English   Suomeksi   På svenska
afterdawn.com > forums > software, operating systems and more > windows - general discussion > any java programmers ?
Show topics
 
Forums
Forums
Any Java Programmers ?
  Jump to:
 
Posted Message
damo_red
Member
_
24. October 2006 @ 07:15 _ Link to this message    Send private message to this user   
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
ditri
Junior Member
_
24. October 2006 @ 21:24 _ Link to this message    Send private message to this user   
I think you should put the statement that checks the grades inside the loop.

do
{
grade = keyboard.nextInt();

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;
}
while (grade > stop);

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);
afterdawn.com > forums > software, operating systems and more > windows - general discussion > any java programmers ?
 

Digital video: AfterDawn.com | AfterDawn Forums
Music: MP3Lizard.com
Gaming: Blasteroids.com | Blasteroids Forums | Compare game prices
Software: Software downloads
Blogs: User profile pages
RSS feeds: AfterDawn.com News | Software updates | AfterDawn Forums
International: AfterDawn in Finnish | AfterDawn in Swedish | AfterDawn in Norwegian | download.fi
Navigate: Search | Site map
About us: About AfterDawn Ltd | Advertise on our sites | Rules, Restrictions, Legal disclaimer & Privacy policy
Contact us: Send feedback | Contact our media sales team
 
  © 1999-2025 by AfterDawn Ltd.

  IDG TechNetwork