I am trying to determine if each input a user provides is the max or min out of all of their inputs, and then assign that input to a variable high or low
int inputnum = 0;
double sum = 0;
double lastinput = 0;
double high;
double low;
double average;
Scanner input = new Scanner(System.in);
high = 0;
low = 0;
do {
System.out.println("Enter a number. Type 0 to quit.");
lastinput = input.nextDouble(); //reads input
sum += lastinput; //add to sum
if (lastinput != 0) {
inputnum += 1; //counts number of inputs (except 0)
}
if (lastinput > high && lastinput != 0) {
high = lastinput;
}
if (lastinput < low && lastinput != 0) {
low = lastinput;
}
average = (sum / inputnum);
} while (lastinput !=0); //repeat unless user inputs 0
The problem is that I cannot declare the variable without assigning it a value (for example 0). If a user inputs 3, 5, and 7 for example, the low value is still defined as 0.