i am having trouble with getting the average of numbers that a user enters (will divide later once as i can get the sum of all of their numbers....). they can enter as many as they like. sorry about the brackets lining up... it was perfect in java, but when copied over, it threw everything out of line... :p here is what i have (i have questions inserted):
Code:double input;
double max=0;
double min=0;
double average = 0;
double range = 0;
String message = "";
int count = 0;
double numbers = 0;
double numbersSum = 0;
do
{
//Prompts user for their input //this does not get repeated every time a number is entered
Scanner in = new Scanner(System.in);
System.out.print("What is your input? (enter -1 to terminate this program: ");
input = in.nextDouble();
// this gets the first number, and sets it to the min and max variables
for (count=0; count < 1; count++);
{
if (count == 0)
{
max = input;
min = input; // can't you set input=max and min?
}
}
System.out.println ("numbers:" + max + min);
for (count=0; count < 100; count++); // how do you make the restriction unlimited?
{
numbers = (Character.getNumericValue(input.charAt(count))); //double is being
dereferenced... how can i fix this? also, i don't think i'm doing this right... i'm getting the numbers in each input seperatley, right?
numbersSum = numbersSum + numbers; // the sum of all the numbers the user added, so
they can be divided by 2 later
}
System.out.print ("the numbers added up are: " + numbersSum + ".");
average = ((numbersSum)/2);
range = (max-min);
// this updates the max value
while (in.hasNextDouble())
{
input = in.nextDouble();
if (input > max)
{
max = input;
}
}
// this updates the min value
while (in.hasNextDouble())
{
input = in.nextDouble();
if (input < min)
{
min = input;
}
}
}
while (input != -1);
System.out.println("The average of these two inputs is: " + average + ".");
System.out.println("The range of these two inputs is: " + range + ".");
System.out.println(message);

