title: "Enter another number (Y/N?)" process starting over instead of continuing when "Y"
body: <p>I have two programs:</p>
  
  <p>Score.java set to do the following: </p>
  
  <ul>
  <li>read scores from the keyboard and print their average.  </li>
  <li>The scores will be numeric and may include a decimal part.  </li>
  </ul>
  
  <p>For example a score might be 8.73 or some such.  Different contests will have different numbers of judges.  It will keep asking for and reading in scores until the user types 'done'.  The program will then print the total score, the number of scores and the average score.  The program will then prompt the user to see if there are any more contestants.  If there are begin prompting for scores again.  If there are no more then exit the program." I have it set to stop the program when you enter "N", and set to add future entries to the calculation after entering "Y".</p>
  
  <pre><code>import java.util.Scanner;
  
  // This is the Score program
  // Written by me
  
  public class Score
  {
      public static void main(String args[])
      {
          Scanner game = new Scanner(System.in);
          double num = 0.0;
          double sum = 0.0;
          int cnt = 0;
  
          while (true)
          {
              System.out.println("Enter as many non-negative integers as you like ");
              System.out.println("one at a time and I will find the average");
              System.out.println("Enter done to stop entering numbers");
  
              System.out.print("enter number: ");
              String ans = game.next();
              while (!ans.equals("done"))
              {
                  num = Double.parseDouble(ans);
                  sum = sum + num;
                  cnt = cnt + 1;
  
                  System.out.print("enter number: ");
                  ans = game.next();
              }
              System.out.println(cnt);
              System.out.println(sum);
  
              System.out.println("Total Score " + sum + " count scores " + cnt + " avg score " + sum / cnt);
  
              System.out.println("Enter another contestant (Y/N)?");
              String str = game.next();
              if (!str.equals("Y"))
                  break;
          }
      }
  }
  </code></pre>
  
  <p>While the above process works, I cannot get my second program, Olympic.java, to work properly after typing "Y" to add more scores. Instead, it starts a whole new calculation of average instead of adding to the previous calculations:</p>
  
  <pre><code>import java.util.Scanner;
  
  // This is the Olympic program
  // Written by me
  
  public class Olympic
  {
      public static void main(String args[])
      {
          Scanner game = new Scanner(System.in);
          double num = 0.0;
          double sum = 0.0;
          int cnt = 0;
          double highscore = Double.MAX_VALUE;
          double lowscore = Double.MIN_VALUE;
  
          while (true)
          {
              System.out.println("Enter as many non-negative integers as you like ");
              System.out.println("one at a time and I will find the average");
              System.out.println("Enter done to stop entering numbers");
  
              System.out.print("enter number: ");
              String ans = game.next();
              lowscore = game.nextDouble();
              highscore = game.nextDouble();
              while (!ans.equals("done"))
              {
                  num = Double.parseDouble(ans);
                  sum = (sum + num) - lowscore - highscore;
                  cnt = cnt + 1;
  
                  System.out.print("enter number: ");
                  if (num &gt; highscore)
                  {
                      highscore = num;
                  }
                  if (num &lt; lowscore)
                  {
                      lowscore = num;
                  }
                  ans = game.next();
              }
              System.out.println("Throwing out low score " + lowscore + " and high score " + highscore);
              System.out.println("Total Score " + sum + " count scores " + cnt + " avg score " + sum / cnt);
  
              System.out.println("Enter another contestant (Y/N)?");
              String str = game.next();
              if (!str.equals("Y"))
                  break;
          }
      }
  }
  </code></pre>