/* This file provides an implementation for library MyStats.

   Names declared:
      EOFMarker, the string indicating the EOF marker
      FindMinMaxAverage(), finds the smallest, largest, and average
------------------------------------------------------------------*/

#include "MyStats.h"

#include <iostream.h>

/*-----------------------------------------------------------------
   This function finds the smallest, largest, and average values
   in a list.

   Input:   A sequence of real values
   Return:  Min, the smallest value in the sequence,
            Max, the largest value in the sequence, and
            Average, the average of the values in the sequence
------------------------------------------------------------------*/

void FindMinMaxAverage(double& Min, double& Max, double& Average)
{
   int
      Count = 0;
   double
      Value,
      Sum = 0.0;

   cout << "\nFirst value ("           // get the first value
        << EOFMarker << " to quit): ";
   cin >> Value;

   Min = Max = Value;                  // initialize the params

   while (!cin.eof())                  // while more data
   {
      Count++;                         //   increment Count

      Sum += Value;                    //   add Value to Sum

      if (Value < Min)                 //   compare Value to Min
         Min = Value;                  //   save it if it's smaller
      else if (Value > Max)            //   compare Value to Max
         Max = Value;                  //   save it if it's larger

      cout << "Next value ("          // get the next value
           << EOFMarker << " to quit):  ";
      cin >> Value;
   }

   Average = Sum / Count;                 // compute Average
}
