// B.F.Caviness 09/03/03 for CISC181
// modifed by P. Conrad, for CISC181 02/11/05

// A first example of using a while statement.  Reading five integers and 
// computing the smallest and largest using a counter controlled repetition.
//-----------------------------------------------------------------

#include <iostream>
using std::cin;
using std::cout;
using std::endl;

int main(void)
{
  int number, smallest, largest;

  cout << "Please enter 5 numbers:" << std::flush;
  cin >> number;		// Read first number.
  smallest = largest = number;	// Initialize smallest and largest.

  int loop_counter = 1;		// Initialize loop counter.
  while (loop_counter < 5)
  {
     cin >> number;		// Read 2nd thru 5th
     if (number < smallest)
       smallest = number;
     if (number > largest)
       largest = number;
     loop_counter = loop_counter + 1;
  }

  cout << "smallest is " << smallest << endl;
  cout << "LARGEST is "  << largest  << endl;

  return 0;
}

//-----------------------------------------------------------------
// The important lesson from this example is the idiom for computing
// the largest or smallest from a list of numbers.  In particular, the
// correct way to initialize the process.
//
// OBSERVATION:  The main limitation of this program is that it only works
// for exactly five integers.  See the file min-max-a.cc for a first
// solution to this limitation.

