/* File: min2.c Report the smallest item entered by the user. Fixes the problem where teh user quits without entering a number. */ #include // Inlcude the following to define the INT_MAX constant #include int main() { int min, n, stop ; int count ; printf("Enter some positive numbers. When you are done, type -1.\n") ; min = INT_MAX ; // everything is <= INT_MAX stop = 0 ; // don't stop count = 0 ; while (!stop) { printf("? ") ; scanf("%d", &n) ; if (n == -1) { stop = 1 ; } else { count = count + 1 ; if (n < min) min = n; } } // end of while if ( count > 0 ) { printf("The smallest number out of %d numbers entered was: %d\n", count, min) ; } else { printf("No numbers were entered.\n") ; } return 0 ; }