//Devin Scheu CS1A Chapter 3, P. 143, #4
//
/**************************************************************
*
* CALCULATE AVERAGE RAINFALL
* ____________________________________________________________
* This program calculates the average rainfall for three months
* based on month names and rainfall amounts.
*
* Computation is based on the formula:
* average = (rainfall1 + rainfall2 + rainfall3) / 3
* ____________________________________________________________
* INPUT
* month1 : Name of the first month (as a string)
* month2 : Name of the second month (as a string)
* month3 : Name of the third month (as a string)
* rainfall1 : Rainfall for the first month (in inches, as a double)
* rainfall2 : Rainfall for the second month (in inches, as a double)
* rainfall3 : Rainfall for the third month (in inches, as a double)
*
* OUTPUT
* average : The average rainfall for the three months (in inches)
*
**************************************************************/
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main () {
//Variable Declarations
string month1; //INPUT - Name of the first month (as a string)
string month2; //INPUT - Name of the second month (as a string)
string month3; //INPUT - Name of the third month (as a string)
float rainfall1; //INPUT - Rainfall for the first month (in inches, as a float)
float rainfall2; //INPUT - Rainfall for the second month (in inches, as a double)
float rainfall3; //INPUT - Rainfall for the third month (in inches, as a double)
float sum; //PROCESSING - The sum of the rainfall amounts
float average; //OUTPUT - The average rainfall for the three months (in inches)
//Prompt for Input
cout << "Enter the name of the first month: ";
getline(cin, month1);
cout << "\nEnter the rainfall for " << month1 << " (in inches): ";
cin >> rainfall1;
cin.ignore(); //Clear input buffer
cout << "\nEnter the name of the second month: ";
getline(cin, month2);
cout << "\nEnter the rainfall for " << month2 << " (in inches): ";
cin >> rainfall2;
cin.ignore(); //Clear input buffer
cout << "\nEnter the name of the third month: ";
getline(cin, month3);
cout << "\nEnter the rainfall for " << month3 << " (in inches): ";
cin >> rainfall3;
cin.ignore(); //Clear input buffer
cout << endl << "OUTPUT: " << endl;
//Calculate Sum
sum = rainfall1 + rainfall2 + rainfall3;
//Calculate Average
average = sum / 3.0;
//Output Result
cout << fixed << setprecision(2) << "The rainfall for "<< month1 <<" is: " << rainfall1 << " inches." << endl;
cout << fixed << setprecision(2) << "The rainfall for "<< month2 <<" is: " << rainfall2 << " inches." << endl;
cout << fixed << setprecision(2) << "The rainfall for "<< month3 <<" is: " << rainfall3 << " inches.";
cout << fixed << setprecision(2) << "\nThe average rainfall for " << month1 << ", " << month2 << ", and " << month3 << " is " << average << " inches." << endl;
} //end of main()