Electrical and Computer Engineering
43 of 45
UAH
CPE 112
Problem Solving Case Study
•void Get12Amounts( /*out*/ float& sum ) // Sum of rainfall
•
•// Inputs 12 monthly rainfall amounts, verifying that
•// each is nonnegative, and returns their sum
•// Postcondition:
•//     12 nonnegative rainfall amounts have been read
•//  && sum == sum of the 12 input values
•{
•    int   count;       // Loop control variable
•    float amount;      // Rainfall amount for one month
•
•    sum = 0;
•    for (count = 1; count <= 12; count++)
•    {
•        cout << "Enter rainfall amount " << count << ": ";
•        GetOneAmount(amount);
•        sum = sum + amount;
•    }
•}
•
•