1

I'm new to programming and i'm way out in left field on this one... I'm trying to write a program that takes takes numerical grade inputs and tells you what the letter grade is. The program must keep running until the user hits 'E' or 'e'.

Here's my problem: with what I have written, the Java isnt finding any errors, how ever when I run the program, it either locks up or prints out all the letter grades regardless of my values. ANY help would be greatly appreciated!

Code listed here:

import java.util.Scanner;
public class Grade {
    public static void main(String[] args) {
	String userInput;
	int grade;
	boolean moreOrder = true;
	
	//Prompts the user to input numeric grade
	System.out.println("Enter your numeric grade (0 to 100) or press 'E' to exit.");
	
	while (moreOrder) {
	    
	}
	// creates the scanner class to take inputs from keyboard
	Scanner keyboard = new Scanner(System.in);
	userInput = keyboard.nextLine();
	grade = userInput.charAt(0);
	char letter;
	
	// Shows the program grabs the appropriate letter grade
	if (grade >=90)
	{
	    letter ='A';
	    System.out.println("Your letter grade is " + letter + ".");
	}
	else if (grade >=80)
	{
	    letter ='B';
	    System.out.println("Your letter grade is " + letter + ".");
	}
	else if (grade >=70);
	{
	    letter ='C';
	    System.out.println("Your letter grade is " + letter + ".");
	}
	
	 if (grade >=60);
	{
	    letter ='D';
	    System.out.println("Your letter grade is " + letter + ".");
	}
	 if (grade <=59);
	{
	    letter ='F';
	    System.out.println("Your letter grade is " + letter + ".");
	}
	
	 if (grade == 'E' || grade == 'e')
	{
	    System.out.println("The program has ended. See you next time.");
	    moreOrder = false;
	}
	else
	    System.out.println("Invalid choice, try again.");
	
	    
	}
    }

Edited by Ezzaral: Old thread, bumped for no reason brought back to top. Closing so people don't try to solve it.

Votes + Comments
Code tags on first post, thank you.
4
Contributors
5
Replies
8
Views
8 Years
Discussion Span
Last Post by BestJewSinceJC
0

For B you have to put greater than 80 and less than 90.
Fix that for the other grades too.
The way you have it now, entering 90 will output all grades higher than F.
That should work.

Edited by Grn Xtrm: n/a

0

I placed the loop in there to keep the program "asking for inputs" until a condition was met (i.e. User inputs 'E' or 'e'). But obviously i might have missed something

0

I placed the loop in there to keep the program "asking for inputs" until a condition was met (i.e. User inputs 'E' or 'e'). But obviously i might have missed something

Yes, but a while loop runs until the condition is no longer true. For example:

int i = 0;

while(i < 10){
System.out.println(i);
i++; // same as i = i + 1;
}

^ The above will print out 0 through 9.
The below code will just continuously print 0.

int i = 0;

while(i < 10){ //I is always less than ten! Just like in your code above where 'moreOrder' is always true! So what's inbetween the brackets just keeps happening.
System.out.println(i);
}