SumAndAverage Program Help!
Solved! Answer is down below if anyone is interested.
----------------
Almost have it figured out... However, every time the program loops, I think the sum and average get reset to sum=0 and average=1, and I cannot figure out a way around it. Any help would be greatly appreciated!
--------------------------------------…
Write a program that reads an unspecified number of integers from the keyboard. When the user enters a ‘0’ this signifies the end of data entry and doesn’t itself count as one of the entered values. The program must compute the sum of all the numbers and the average value of the numbers. The program must be named “SumAndAverage”.
Code:
public class SumAndAverage {
public static void main(String [] args) {
int number;
int sum=0;
int average=1;
int count = 1;
System.out.print("Enter number: ");
number = Keyboard.readInt();
while (number != 0) {
System.out.print("Enter number: ");
number = Keyboard.readInt();
sum = sum + number;
average = sum / count;
count ++;
}
count = count -1;
System.out.println("The sum of these " + count + " numbers is: " + sum);
System.out.println("The average of these " + count +" numbers is: " + average);
}
}