title: Create an Averager using do-while loop
body: <p>This program has to prompt the user to input a positive number if they do     not and end ONLY when the user enters -1. The problem I'm running into is how to calculate the actual average after the user enters a negative number and the program keeps going. It calculates the negative number when it shouldn't. How do I get it to print the correct average even after the user enters a negative?</p>
  
  <pre><code>package averager;
  
  import java.util.Scanner;
  
  public class Averager {
  
      public static void main(String[] args) {
          double sum = 0; // use for storing addition to all entered values..
          double num, count = 0;
          Scanner scan = new Scanner(System.in);
  
          do {
  
              System.out.print("Enter any positive number, enter -1 to quit: ");
              num = scan.nextDouble();
              sum = sum + num;
              count++;
  
              if (num &lt;= 0) {
                  System.out.println("Please enter a positive number.");
  
              } else if (num != -1) {
                  System.out.println("Average is : " + sum + "/" + count + " = " + (sum / count));
              } else if (num == -1) {
                  System.out.println("Average is : " + (sum + 1) + "/" + (count - 1) + " = " + ((sum + 1) / (count - 1)));
  
  
              }
  
          } while (num != -1);
  
      }
  
  }
  </code></pre>