Electrical and Computer Engineering
45 of 45
UAH
CPE 112
Problem Solving Case Study
•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 output of an error message)
•//  && amount >= 0.0
•{
•    do
•    {
•        cin >> amount;
•        if (amount < 0.0)
•            cout << "Amount cannot be negative. Enter again: ";
•    } while (amount < 0.0);
•}