/* This function reliably inputs a real value from the keyboard.

   Receive: Number, a (reference to a) real variable
   Input:   The user's value, stored in Number
   Return:  Number, guaranteed to be a user response AND a real
            value
            (Exception: if the user enters the end-of-file mark)
------------------------------------------------------------------*/

#include <iostream.h>
#include <limits.h>                 // provides INT_MAX

void GetNumber(double& Number)
{
   const char                       // error message
      InvalidValue[] =
         "\n*** GetNumber: input value must be numeric.\n",
      Prompt[] = "\nNumber ? ";

   cout << Prompt;                  // prompt for a number
   cin >> Number;                   // input the user's response

   while(!cin.eof() && cin.fail())  // trap the user-- while neither
   {                                // end-of-file nor valid input:
      cerr << InvalidValue;         //   display the error msg
      cin.clear();                  //   reset the state bits
      cin.ignore(INT_MAX, '\n');    //   skip the invalid entry
      cout << Prompt;               //   prompt for a number
      cin >> Number;                //   input the user's response
   }
}




