//Sam Partovi CS1A Chapter 3, P. 143, #4
//
/*******************************************************************************
*
* COMPUTE AVERAGE RAINFALL
* ____________________________________________________________
* This program computes the average rainfall of 3 months based on given
* rainfall measurements for each month.
*
* Average rainfall is calculated with the following formula:
* avgRainfall = ( firstRainfall + secondRainfall + thirdRainfall ) / monthCount
* ____________________________________________________________
*INPUT
* firstMonthName : Name of the first month
* secondMonthName : Name of the second month
* thirdMonthName : Name of the third month
* firstRainfall : Rainfall measurement of the first month (in)
* secondRainfall : Rainfall measurement of the second month (in)
* thirdRainfall : Rainfall measurement of the third month (in)
* monthCount : Number of months to calculate average
*
*OUTPUT
* avgRainfall : The average rainfall in inches
*
******************************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
//Variable dictionary
string firstMonthName; //INPUT - Name of the first month
string secondMonthName; //INPUT - Name of the second month
string thirdMonthName; //INPUT - Name of the third month
float firstRainfall; //INPUT - Rainfall measurement of the first month (in)
float secondRainfall; //INPUT - Rainfall measurement of the second month (in)
float thirdRainfall; //INPUT - Rainfall measurement of the third month (in)
int monthCount; //INPUT - Number of months to calculate average
float avgRainfall; //OUTPUT - The average rainfall in inches
//Initialize program variables
monthCount = 3;
//Prompt user for month names
cout << "First month name: ";
cin >> firstMonthName;
cout << "Second month name: ";
cin >> secondMonthName;
cout << "Third month name: \n";
cin >> thirdMonthName;
//Prompt user for rainfall in inches
cout << "Enter the rainfall (inches) for the month of " << firstMonthName
<< ": \n";
cin >> firstRainfall;
cout << "Enter the rainfall (inches) for the month of " << secondMonthName
<< ": \n";
cin >> secondRainfall;
cout << "Enter the rainfall (inches) for the month of " << thirdMonthName
<< ": \n";
cin >> thirdRainfall;
//Compute average rainfall
avgRainfall = (firstRainfall + secondRainfall + thirdRainfall) / monthCount;
//Output results
cout << "\nThe average rainfall for the months of " << firstMonthName << ", "
<< secondMonthName << ", " << "and " << thirdMonthName << " is " <<
setprecision(4) << avgRainfall << " inches." << endl;
return 0;
}