CH11_4
http://www.chegg.com/homework-help/questions-and-answers/question-please-help-question-write-program-uses-structure-store-following-weather-data-pa-q3363800
https://www.daniweb.com/software-development/cpp/threads/395877/weather-structure-program
https://www.daniweb.com/software-development/cpp/threads/395877/weather-structure-program
// This program collects the weather statistics for a year. The data it collects is total rainfall, high temp, low temp, average temp.
//Programming Challenge 11.4
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
struct Weather
{
double rainfall;
double high_temp;
double low_temp;
double avg_temp;
};
// Function Prototypes
/*double getTotalrain(double);
double getAvgrain(double);
double getAverageTemp(double);
double getHighTemp(double);
double getLowTemp(double);*/
int main()
{
const int NUM_MONTHS = 12; //Number of Months
Weather months[NUM_MONTHS]; //Array of 12 months
int index; //Loop counter
double annualRainfall=0.0,averageRainfall;
// Get rainfall for each month.
for (int index = 0; index < NUM_MONTHS; index++)
{
// Get months rainfall
cout << "Enter the rainfall in inches for month #:";
cout << (index + 1) << ": ";
cin >> months[index].rainfall;
cout<<months[index].rainfall;
annualRainfall+=months[index].rainfall;
averageRainfall=annualRainfall/12;
}
// Display total rainfall.
cout << "The total rainfall for the year is ";
cout << annualRainfall
<< " inches." << endl;
// Display the average rainfall from the year
cout << "The average rainfall for the year is ";
//float average = months[index].rainfall / 12;
cout << averageRainfall << " inches." << endl;
cin.get();
return 0;