Changing a variable though a module in a loop (java)
<p>So I am trying to write a simple program for my Java class and I have asked the teacher for help however, this is a distance learning class and am not getting much help from that direction. So here I am. </p>

<p>The problem we have been asked to solve is to create a program that will
(1) ask the user for a number , 
(2) find the sum  of all user defined numbers ,
(3) find the average of these numbers , 
(4) then out put them back to the user.</p>

<p>I use the numbers not only to line through things I have finished but because they must be separate modules to be called. </p>

<p>How can i get the userNum variable to update durring the while statments. Currently they are not. OR is there a simpler way to do this that im overlooking. Any help is greatly appreciated. Thank you.</p>

<pre><code>public class P2 {

   public static void main(String[] args) {

        int userNumCount = 1;

        double userNum = input();
        double userSum = sum(userNum);
        double userAverage = average(userSum, userNumCount);

        sum(userNum);

        while (userNum != 0 &amp;&amp; sum(userNum) &lt;= 100){
            ++userNumCount;          
            output(userSum, userAverage);
            input();
            sum(userNum);
            average(userSum, userNumCount);
        }//end else
        while (userNum != 0 &amp;&amp; sum(userNum) &gt;=100){
            ++userNumCount;
            JOptionPane.showMessageDialog (null, "Warning, your sum is currently over 100!!!!!"); 
            output(sum(userNum), userAverage);
            input();
            sum(userNum);
            average(userSum, userNumCount);
    }//end else
        if (input() == 0){
            output(userSum, userAverage);
            JOptionPane.showMessageDialog (null, "Thank you for using this program have a nice day.");
    }//end else if


    }//end main module
    public static double input(){
        String userNumString;
        userNumString = JOptionPane.showInputDialog("Please enter your number or input 0 to end the program.");
        double userInput = Double.parseDouble (userNumString); 
        return userInput;
    }//end input module
    public static double sum(double userNum){  
        double userSum =+userNum;
        return userSum;
    }//end sum module
    public static double average (double userSum, int userNumCount){
        double userAverage = userSum/userNumCount;
        return userAverage;
    }//end average module
    public static void output (double userSum, double userAverage){
        JOptionPane.showMessageDialog (null, "The sum of the numbers input so far is: " + userSum + ". And the Average is " + userAverage + "." );
    }//end output module
}//end class
</code></pre>
