/**********************************
  File:  hw2p2.c

read a list of positive integers, 
and display the smallest.  0 is the
sentinel value.
***********************************/

#include <stdio.h>
#include "simpio.h"


/* 

i is the value just entered
min is the smallest value so far, including the value just entered.

When the first integer is entered, min is set to that value, since it's
the smallest value so far.  For every other integer entered, it is compared
to min and min is updated if necesary.

*/

void main()
{
  int i=0, min=0;

  printf("Enter an integer: ");
  min = GetInteger(); /* initialize min to be the first integer in the list */

  while (TRUE) {     /* keep reading integers until sentinel found */
    printf("Enter an integer: ");
    i = GetInteger();
    if (i == 0)   /* sentinel found, stop reading integers */
      break;
    if (i < min)  /* smaller integer read in, update min */
      min = i;
  }
  printf("The smallest integer was: %d\n", min);
}


