Question: I'm writing a program that allows the user to input integers in the range 0 to 100. Scores are inputted until the sentinel value 999

I'm writing a program that allows the user to input integers in the range 0 to 100. Scores are inputted until the sentinel value 999 is entered. If a number outside the range is entered,(other than 999) the user is told the number is not allowed and is then prompted for a new one. This is what I have so far:

import java.util.Scanner;

public class TestAverage {

public static void main(String[] args) { int total = 0; int count = 0; int score = 0; int min = 0; int max = 0; final int sentinel = 999; Scanner kbd = new Scanner(System.in); System.out.println("Enter test scores, and get lowest score, the "+ "highest score, and the average Enter 999 to quit"); String prompt = "Enter a score [0....100] 999 to quit: "; while (score != sentinel) { System.out.print(prompt); score= kbd.nextInt(); if(score >0 && score < 100){ total+=score; if(count==0){ min=score; max=score; } else{ if(score>max){ max=score; } if(score 100 ){ System.out.printf("%8d,Enter only 0..100 (999 quits)"); } } if(count == 0){ System.out.println("You didn't enter any scores..."); } else{ double average = (double) total / count; System.out.println("Lowest score: " + min); System.out.println("Highest score: " + max); System.out.println("Average score: " + average); System.out.println("There were" +" " + count + " " + "scores."); } } }

I'm trying to get the program to display this message when the user inputs an integer outside the range:

Enter only 0.100 (999 quits)

But anytime I input a number outside the range, it displays the standard message. Are there any tips you could give? Many thanks in advance!!!!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!