/**********************************
  File:  hw2p2-alt.c

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

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


/* this version of problem 2 uses a slightly different approach
than that in hw2p2.c.  Here, instead of using a special case of
GetInteger to initialize min, we include a test within the loop
if min has gotten any value yet.  If (min==0), then it hasn't 
gotten any value yet, and it's assigned the value just entered, no
matter what it is.
*/

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


  while (TRUE) {     /* keep reading integers until sentinel found */
    printf("Enter an integer: ");
    i = GetInteger();
    if (min == 0) /* initialize min to be the first integer in the list */
      min = i;
    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);
}
