Question: Im writing a program that allows the user to input integers in the range from 0 to 100, until the sentinel value 999 is entered
Im writing a program that allows the user to input integers in the range from 0 to 100, until the sentinel value 999 is entered to end the program. Im trying to write a loop that will display a message if the user inputs an integer outside the range from 0 to 100.
This is the message I want to display:
Enter only 0....100, 999 to quit
This is the code I have so far:
import java.util scanner
Public class TestAverage
{
public static void main(String[]args)
{
int score;
int count;
final int sentinel=999;
Scanner kbd= new Scanner(System.in);
System.out.print("Enter test scores, and get lowest score, the highest score, and the average"/n"Enter 999 to quit");
String prompt ="Enter a score [0....100] 999 to quit"
boolean goodScore=(score>= 0 && score <=100);
while (score != sentinel)
{
system.outprint(prompt);
score = kbd.NextInt();
if(goodScore)
{
total+=score;
count++
}
else
{
System.out.print(" Enter only 0....100, 999 to quit");
}
I wrote a boolean message that allows the program to check if the input is within the range. I'm just confused as to where in the loop this message should go.
Prompt feedback would be appreciated. Thanks in advance!!!!!!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
