My program asks a user for test scores and displays the min/max, # of tests, and the average. However, if the score isn't between 0 and 10 I don't want that number used in my calculations. How would I go about doing that in my do/while loop? I've tried entering System.exit(0); after line if (num <= 0 || num >10) System.out.println("Score must be between 10 and 0"); but it breaks my program. Here is my code:
import java.util.*;
public class QuizScoreStatistics {
public static void main (String args[]) {
float max=0;
float min=99;
float avg=0;
float count=0;
float sum=0;
float num;
Scanner scan=new Scanner(System.in);
System.out.println("Please input test scores with values between 0-10.\nEnter 99 to finish.");
num=scan.nextInt();
float temp=num;
do
{
if(num==99)
System.exit(0);
if (num <= 0 || num >10)
System.out.println("Score must be between 10 and 0");
if(num>=0 && num<=100)
{
count++;
sum+=num;
if(num>max )
max=num;
if(num<min)
min=num;
}
} while((num=scan.nextInt())!=99);
// System.out.println("Test Statistics:");
System.out.println("Number of tests: "+count);
System.out.println("Lowest: "+min);
System.out.println("Highest: "+max);;
System.out.printf("Average: " + sum/count);
}
}