Thread: Determining and displaying a range?

1. Determining and displaying a range?

I think this is a relatively simply question but I can't seem to figure it out. Assume a program in which the user enters a collection of numbers. Using a while loop, the program calculates the sum and average for the collection of numbers. How do I go about getting the program to identify the smallest value within the collection, the largest value, and the subsequent range?

2. While reading in the numbers, read in the first number into two variables (highestVal, lowestVal), then as you read in the rest of the values, check to see if the last value you read in is higher than what's in highestVal or lower than what's in lowestVal. If it is, replace it.

Then in the end, just subtract lowestVal from highestVal to get your range.

3. min=max=first input
while input
if input<min
min=input
else if input>max
max =input

range is min to max

4. Yeah, basically what cbastard said. He just made it a little cluttered.

5. I think the clutter was what I needed . The only issue I have now is that the minimum value is being registered as the value entered to end the program. This value isn't taken into account when calculating the average or the sum of the numbers however. Any ideas?

6. I don't understand what you're saying in your second sentence, but why would the minimum value be taken account in calculating the average?

7. In the program, I am using a value that is outside the conceivable realm of the data entry to signal to the program to cease receiving input. So when I plug this number in, the program should take the previous numbers entered to determine the average, the range, etc. For some reason, the value to end the data entry is registering as the minimum value for the group. It is not, however, being used to determine the average, as it shouldn't be. Does that help?

8. Read the input number into a variable called something clever like inputnum. Right after receiving that number check to see if it is one of the special end-the-input numbers. If it is, skip to the code that spits out the results. Otherwise, do your minval/maxval stuff on the input number and repeat the input process.