I have been working on this for awhile, but I was hoping to get input from someone with more experience.
I have to stick with the structure and enum format for the assignment, but I was wondering if anyone had any opinions on the way the high/low temperature sections should be done?
Thanks for your help, I appreciate any hints.
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
struct WeatherInfo
{
double rainfall;
double highTemp;
double lowTemp;
};
enum Month {January, February, March, April,
May, June, July, August,
September, October, November, December};
int main()
{
const int MONTHS = 3;
WeatherInfo month[MONTHS];
int index;
double rainTotal = 0.0;
double tempTotal = 0.0;
double tempHigh = 0.0;
double tempLow = 0.0;
for (index = January; index <= March; index = static_cast<Month>(index +1))
{
cout << "Please enter the rainfall in inches";
cout << (index + 1) << " :";
cin >> month[index].rainfall;
rainTotal += month[index].rainfall;
cout << "Please enter the temperature";
cout << (index + 1) << " :";
cin >> tempTotal;
if ( tempTotal < -100 || tempTotal > 140)
{
cout << "The temperature you entered is invalid" << endl;
cout << "Please re-enter: ";
cin >> tempTotal;
}
if (month[index] > tempTotal)
{
tempHigh += month[index].highTemp;
}
if (month[index] < tempTotal)
{
tempLow += month[index].lowTemp;
}
}
cout << "The total rainfall for the year is " << rainTotal << endl;
cout << "The highest temperature is " << tempHigh << endl;
cout << "The lowest temperature is " << tempLow << endl;
return 0;
}