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
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
Step: 1

Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2

Step: 3

Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started