#include "stdafx.h"
#include <iostream.h>
struct MonthInfo
{
float totalRain;
float highTemp;
float lowTemp;
float avgTemp;
};
struct MonthInfo year[12];
int main(int argc, char* argv[])
{
const int MONTHS = 12;
// Change here
for (int i = 0 ; i < MONTHS ; i++ )
{
cout << "Enter data for month " << i << endl;
cout << "Enter Total RainFall" << endl;
cin >> year[i].totalRain;
do {
cout << "Enter High Temperature" << endl;
cin >> year[i].highTemp;
}while ( year[i].highTemp < -100 || year[i].highTemp > 140 );
do {
cout << "Enter Low Temperature" << endl;
cin >> year[i].lowTemp;
}while (year[i].lowTemp < -100 || year[i].lowTemp > 140 );
year[i].avgTemp = (year[i].highTemp + year[i].lowTemp) / 2;
}
float avgMonthlyRain = 0;
float sum = 0;
float monthlyTempSum = 0;
for(i = 0 ; i < MONTHS ;i++ )
{
sum += year[i].totalRain;
monthlyTempSum += year[i].avgTemp;
}
cout << "Average Monthly Rain is = " << (sum/MONTHS) << endl;
cout << "Total Rainfall for the year = " << sum << endl;
// Finding highest temprature
float highest = -100;
int m = 0; // for keeping the month in which highest year appeared
for (i = 0 ; i < MONTHS ; i++ )
{
if ( year[i].highTemp > highest )
{
highest = year[i].highTemp;
m = i;
}
}
cout << "Highest Temprature " << highest << " Appeared in month "<< m << endl;
// Finding lowest temprature for the year
float lowest = 140;
m = 0; // for keeping the month in which highest year appeared
for (i = 0 ; i < MONTHS ; i++ )
{
if ( year[i].lowTemp < lowest )
{
lowest = year[i].lowTemp;
m = i;
}
}
cout << "Lowest Temprature " << lowest << " Appeared in month "<< m << endl;
cout << "Average of all monthly average temperatures = " << (monthlyTempSum/ MONTHS )<<endl;
cin.get();
cin.get();
return 0;
}
Please help?
Thanx:rolleyes: