I am doing a programming assignment. This program asks you to collect statistics on precipitation and temperatures from the four quarters of a year and print the calculated results. It is an exercise in using enumerated types and arrays. The measurements are entered at the end of every quarter.
Major variables (there are other variables) in the program:
Variable called: month of type Summary_Month (the enumerated type)
Arrays of integers called: low_temp, high_temp, precip
Array of doubles called: avg_temp
You will ask the user to enter the precipitation, low temperature and high temperature for each quarter. As you gather this data, you will calculate the average temperature (using avg_temp) for each quarter by averaging the low and high temperature for that quarter.
After you gather the information you will calculate and output the following:
Total Precipitation for Year, Average Quarterly Precipitation, Average Quarterly Temperature, Highest Temperature for any quarter, Lowest Temperature for any quarter.
I am not getting the right output for average precipitation and temperature and I am not sure how to determine the highest and lowest temperature. Any help will be greatly appreciated.
# include <iostream>
# include <iomanip>
using namespace std;
enum Quarters { March, June, September, December};
int main()
{
const int NUM_QUARTERS = 4;
/*double avg_temp [NUM_QUARTERS]; */
double totalp = 0.0;
double avgt = 0.0;
double avgp = 0.0;
int low_temp [4];
int high_temp [4];
int precip [4];
Quarters monthQuarters;
for (monthQuarters = March; monthQuarters <= December;
monthQuarters = static_cast<Quarters>(monthQuarters +1))
{
cout << "Enter the precipitation for Quarter " << monthQuarters +1 << endl << endl;
cin >> precip[monthQuarters];
cout << endl << endl;
cout << "Enter the low temperature for Quarter " << monthQuarters +1 << endl << endl;
cin >> low_temp[monthQuarters];
cout << endl << endl;
cout << "Enter the high temperature for Quarter " << monthQuarters +1 << endl << endl;
cin >> high_temp[monthQuarters];
cout << endl << endl;
}
for (monthQuarters = March; monthQuarters <= December;
monthQuarters = static_cast<Quarters>(monthQuarters +1))
{
avgt += (low_temp[monthQuarters] + high_temp[monthQuarters]) / 8;
avgp += (precip[monthQuarters] ) / 4;
totalp += precip[monthQuarters];
}
cout << "The Average Temp for the year is " << avgt << endl << endl;
cout << "The Average Precipitation for the year is " << avgp << endl << endl;
cout << "The Total Percipitation for the year is " << totalp << endl << endl;
system ("pause");
return 0;
}