Well, that's your choice.Originally Posted by tomtom1
The thing is, I don't understand why you say that you don't know what you should do. I mentioned a while loop and the checking of the return value of scanf to compare it with 1 in the loop condition:
Notice that my example program has nothing about sum, or about the arithmetic mean ("midpoint"). It is a demonstration of one way of reading integers from standard input until EOF (or a read error) is detected. By getting this right first (after all, it is easy to count the numbers as you are entering them and then compare your count with the result that was printed), you can be more confident that if there's a bug later, it is most likely not because you were reading too few or too many numbers.Code:#include <stdio.h> int main(void) { int count = 0; int input; while (scanf("%d", &input) == 1) { ++count; } printf("%d numbers were read\n", count); return 0; }
Once you are sure about the count, you can add the part about computing the sum. Again, test: that way, if there's a bug later, it is most likely not because you were computing the sum wrongly. Once you have both count and sum, computing the arithmetic mean should not be a problem, and if it is a problem, chances are the bug lies with that computation, not elsewhere.