-
compare input doubles
I am trying to write a program that accepts an undetermined amount of doubles as input and compares those values and determines a high, low and an average. I am using -1 as a sentinel for end of input.
Attached is the code I have so far. It is not setting the minimum value and the average always includes the -1 as a value. I have compensated for the -1 in my average calculation by adding and subtracting 1.
Any help is appreciated.
Brian
-
Well, you were checking for -1 too late, for one. Second, the comparison against max doesn't affect min. Consider that. Also, if the user enters 100 for the lowest number, the min will remain 0!
Finally, the -1 shouldn't find it's way into the calculations. If you were using an array, for instance, you would simply stop calculating/iterating once you reached the sentinal.
-
still problems
I looked at the code you sent and compiled and ran it. It works fine if the numbers are entered descending, however, if the user enters 1,2,3,4,5 as the values, the output for the minimum is 1e+07, or 10,000,000 as it is declared. The value for min doesn't get reset to the lowest value.
Brian
-
Just give it a go. Mentally trace through the program with acending input.
If you see the mistake I made, let me know about it.
Otherwise, if you know what printf() does, let me know.
It's a riddle!