Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

need help please?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class debgrader
{
public static void main(String[] args )
{
int numberofstudents,score;
double next;
char answer, grade;



do
{
System.out.println("Enter scores for all students");
System.out.println("Enter a negative numger after");
System.out.println("You have entered all the scores.");

numberofstudents = 0;
score = 0;
grade=0;
next = SavitchIn.readLineDouble();
while (next >=0)
{
numberofstudents++;
next = SavitchIn.readLineDouble();
}
if (numberofstudents > 0)
System.out.println("Total number of grades " + (numberofstudents));



{

numberofstudents = grade;
if (score >= 90){
grade ='A';
numberofstudents++;}
else if (score >= 80){
grade ='B';
numberofstudents++;}
else if (score >= 70){
grade ='C';
numberofstudents++;}
else if (score >= 60){
grade ='D';
numberofstudents++;}
else if (score < 60){
grade ='F';
numberofstudents++;}
}
System.out.println("Number of A's = " + (numberofstudents++));
System.out.println("Number of B's = " + (numberofstudents++));
System.out.println("Number of C's = "+ (numberofstudents++));
System.out.println("Number of D's = "+ (numberofstudents++));
System.out.println("Number of F's = "+ (numberofstudents++));

System.out.println("Want to score another exam?");
System.out.println("Enter y for yes or n for no.");
answer = SavitchIn.readLineNonwhiteChar();
}while ((answer == 'y') || (answer == 'Y'));
}
}

will not calculate the right number of letter grades
what am I doing wrong ?
please help Thank you.
 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
first of all, make your posted code more readable by using
"code" and "/code" (replace my double quote marks w/ square brackets)
markers to get the proper formatting.


First problem I see in your code is that you initialize grade as 0 and never read into it (from input) any other value.
When you read a grade, you count that as one more student. You never actually record the grade itself.

Create a test input of about 4 grades.
Now write down the names of all your variables on a sheet of scratch paper. These are column headers.
Run through your program using the test input and write down under each
variable (in its column) the values that variable takes on as you run through the program. If it helps you can write down the changes taking place row by row (number the rows in your code and below your columns - graph papaer is good for this).

Are things working the way you planned?
[ November 20, 2004: Message edited by: Elouise Kivineva ]
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey sorry im a newbie, i havent as much knowledge as others in the site, well i just wanted to say when you install your JDK doesnt it give you info if there are errors on your site?
also can i get help like tutorials from someone here?
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Max Labaio-Burreal:
Hey sorry im a newbie, i havent as much knowledge as others in the site, well i just wanted to say when you install your JDK doesnt it give you info if there are errors on your site?
also can i get help like tutorials from someone here?


If this is a new question, you should click "Post a New Topic" to start your own thread.

Layne
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by del barton:

... will not calculate the right number of letter grades
what am I doing wrong ?
please help Thank you.


Have you tried running through your code by hand? What I mean is that you should make a table with all of your variables. Step through the code one line at a time and determine what value that gives to the variables used in that line. Perhaps that will give you an idea of what your program is actually doing. It should also help you see what needs to be fixed to get it working.

HTH

Layne
 
Get me the mayor's office! I need to tell her about this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic