|
|
|
|
|
|
|
//******************************************************************
void GetYesOrNo( /* out */ char& response ) // User response char
// Inputs a character from the user and, if necessary,
// repeatedly prints an error message and inputs another
// character if the character isn't y or n
// Postcondition:
// response has been input (repeatedly, if necessary, along
// with an error message)
// && response == y or n
{
do
{
cin >> response;
if (response != y && response != n)
cout << Please type y or n: ;
// Invariant:
// No previous value of response was y or n
} while (response != y && response != n);
}
//*****************************************************************
void GetOneAmount( /* out */ float& amount ) // Rainfall amount
// for one month
// Inputs one month's rainfall amount and, if necessary,
// repeatedly prints an error message and inputs another
// value if the value is negative
// Postcondition:
// amount has been input (repeatedly, if necessary, along
// with an error message)
// && amount >= 0.0
{
do
{
cin >> amount;
if (amount << 0.0)
cout << Amount cannot be negative. Enter again:
<< endl;
|
|
|
|
|
|