title: Java: Finding the Highest and Lowest Score
body: <p>I'm struggling with a problem I have in my Java class. First here are my directions to the program so you understand what I'm trying to do:</p>
  
  <p>Write an application that allows a user to enter any number of test scores until the user enters 999. If the score entered is less than 0 or more than 100, display an appropriate message and do not use the score. After the scores have been entered, display the number of scores entered, the high score, the lowest score, and the arithmetic average.</p>
  
  <p>---There are several things going wrong. My if statement is not validating the answer right if it doesn't equal 1 or 999. It works the first time, but if I put the answer in wrong, it goes to the while statement instead of prompting the user to re-enter either number 1 or 999.
  ---Second, I can't get the lowest score, but the highest works.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>package chp6homework;
  import java.util.Scanner;
  public class TestScoreStatistics {
  
      public static void main(String[] args) {
          Scanner input = new Scanner(System.in);
          int testScore;
          int totalTests = 0;
          int totalSum = 0;
          int answer;
          double average = 0;
          int hightScore = 0;
          int lowestScore = 0;
  
          // Prompts user for input
          System.out.print("Enter 1 to input a score.\n");
          System.out.print("Enter 999 to get results and exit. &gt;&gt; ");
          answer = input.nextInt();
  
          if(answer != 1 &amp;&amp; answer != 999)
          {
              System.out.print("Invaild number!\n");
              System.out.print("Enter 1 to input a score.\n");
              System.out.print("Enter 999 to get results and exit. &gt;&gt; ");
              answer = input.nextInt();
          }
  
           while(answer == 1)
           {
              System.out.print("Please enter a test score &gt;&gt; ");
              testScore =  input.nextInt();
  
              if(testScore &lt; 0 || testScore &gt; 100)
              {
                  System.out.print("Invalid score! \n");
                  System.out.print("please enter a score that is not less than zero and" +
                          " and not more than 100. &gt;&gt; ");
                  testScore =  input.nextInt();
              }
              totalSum = totalSum + testScore;
              ++totalTests;
  
              lowestScore = testScore;
  
              if(testScore &gt; hightScore)
              {
                  hightScore = testScore;
              }
              else if(testScore &lt; lowestScore) 
              {
                  lowestScore = testScore;
              }
  
              System.out.println("Your score was processed.");
              System.out.print("Enter 1 to input a score.\n");
              System.out.print("Enter 999 to get results and exit.\n");
              answer = input.nextInt();
  
           }
  
          average = totalTests * totalSum;
  
          System.out.println("The number of tests: " + totalTests);
          System.out.println("The total tests are: "+ totalSum);
          System.out.println("The average of scores is: " + average);
          System.out.println("Highest score: " + hightScore);
          System.out.println("Lowest score: " + lowestScore);
          }
  }
  </code></pre>