I am trying to work on a tutorial in my Java book and I got stuck on a piece of the programming.
What this is supposed to do is test scores entered between 0-100 are counted and inputted into a variable. This works. The next part is that any number outside of that range prompts an error message and should return to the prompt to allow further scores to be entered. This is where it is broken. The last piece is that the number 999 is the specific key to tell the program to average the scores and display the it. This works. So what I am hoping someone might be able to help me with the second part as everything I have tried has failed and I figure a fresh set of eyes may be able to spot where I am going wrong.
I have been running this code in netbeans
public class TestScoreApp
public static void main(String args)
// display operational messages
System.out.println("Please enter test scores that range from 0 to 100.");
System.out.println("To end the program enter 999.");
System.out.println(); // print a blank line
// initialize variables and create a Scanner object
double scoreTotal = 0;
int scoreCount = 0;
int testScore = 0;
Scanner sc = new Scanner(System.in);
// get a series of test scores from the user
while (testScore <= 100)
// get the input from the user
System.out.print("Enter score: ");
testScore = sc.nextInt();
// accumulate score count and score total
if (testScore <= 100)
scoreCount = scoreCount + 1;
scoreTotal = scoreTotal + testScore;
else if (testScore == 999)
scoreCount = scoreCount + 0;
else if (testScore > 100)
System.out.println("Invalid Number, Please Try Again");
// display the score count, score total, and average score
double averageScore = scoreTotal / scoreCount;
String message = "\n" +
"Score count: " + scoreCount + "\n"
+ "Score total: " + scoreTotal + "\n"
+ "Average score: " + averageScore + "\n";