// simple program using a sentinel-controlled while loop // reads a number of integers from the terminal // and computes (and outputs) both the smallest // and the largest // User must type -1 to indicate no more integers #include main () { int numb = -1, min=0, max = 0; cout << "This program computes the smallest and "; cout << endl; cout << "largest of the input positive integers."; cout << endl; cout << endl; cout << "Please input a positive integer" << endl; cout << "(-1 if no more input): "; cin >> numb; min = max = numb; while (numb != -1) { if (numb < min) min = numb; if (numb > max) max = numb; cout << "Please input a positive integer" << endl; cout << "(-1 if no more input): "; cin >> numb; } if (min != -1) { // at least 1 number was input cout << endl; cout << "The smallest number is "; cout << min << endl; cout << "The largest number is "; cout << max << endl; } else { cout << "ERROR: no input numbers found!"; cout << endl; } return 0; }