|
|
|
|
|
|
|
do
{
Get12Amounts (sum);
cout << Average rainfall is <<< sum / 12.0
<< inches << endl << endl;
cout << Do you have another recording site? (y or n) ;
GetYesOrNo(response);
// Invariant:
// Rainfall amounts have been processed for
// current site and all previous sites
// && All previous values of response were y
} while (response == y);
return 0;
}
//******************************************************************
void Get12Amounts( /* out */ float& sum ) // Sum of 12 rainfall
// amounts
// Inputs 12 monthly rainfall amounts, verifying that
// each is nonnegative, and returns their sum
// Postcondition:
// 12 rainfall amounts have been read and verified to be
// nonnegative
// && 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++)
{
// Invariant (prior to test):
// sum == sum of the first count-1 input values
// && 1 <= count <= 13
cout << Enter rainfall amount << count << : << endl;
GetOneAmount (amount);
sum = sum + amount;
}
}
|
|
|
|
|
|