Please help me with this question! Write a program that uses a structure to stor
ID: 3624744 • Letter: P
Question
Please help me with this question!
Write a program that uses a structure to store the following weather data for a particular month:
Total Rainfall
High Temperature
Low Temperature
Average Temperature
The program should have an array of 12 structures to hold weather data for an entire year. When the program runs, it should ask the user to enter data for each month. (The average temperature should be calculated.) Once the data are entered for all the months, the program should calculate and display the average monthly rainfall, the total rainfall for the year, the highest and the lowest temperatures for the year (and the months they occurred in), and the average of all the monthly average temperatures.
Input Validation: Only accept the temperature within the range between -100 and +140 degrees Fahrenheit.
Explanation / Answer
please rate - thanks
#include <iostream>
using namespace std;
struct weather
{
double total;
double high;
double low;
double average;
};
int main()
{weather month[12];
string monthname[12]={"January","February","March","April","May","June","July","August",
"September","October","November","December"};
int i=0,high=0,low=0;
double total=0,maverage,atotal=0,aaverage;
cout<<"Enter rain information for: ";
for(i=0;i<12;i++)
{cout<<monthname[i]<<endl;
cout<<"rain fall: ";
cin>>month[i].total;
cout<<"high temperature: ";
cin>>month[i].high;
while(month[i].high<-100||month[i].high>140)
{cout<<"Invalid entry-must be between -100 through 140 ";
cout<<"high temperature: ";
cin>>month[i].high;
}
cout<<"low Temperature: ";
cin>>month[i].low;
while(month[i].low<-100||month[i].low>140)
{cout<<"Invalid entry-must be between -100 through 140 ";
cout<<"low Temperature: ";
cin>>month[i].low;
}
month[i].average=(month[i].high+month[i].low)/2;
total+=month[i].total;
atotal+=month[i].average;
}
maverage=total/12;
aaverage=atotal/12;
for(i=1;i<12;i++)
{if(month[i].high>month[high].high)
high=i;
if(month[i].low>month[low].low)
low=i;
}
cout<<" SUMMARY ";
cout<<"Total rain fall: "<<total<<endl;
cout<<"Average Monthly Rainfall: "<<maverage<<endl;
cout<<"Average Monthly Average Temperature: "<<maverage<<endl;
cout<<"Highest Temperature: "<<month[high].high<<endl;
for(i=0;i<12;i++)
if(month[i].high==month[high].high)
cout<<monthname[i]<<" ";
cout<<" Lowest Temperature: "<<month[low].low<<endl;
for(i=0;i<12;i++)
if(month[i].low==month[low].low)
cout<<monthname[i]<<" ";
cout<<endl;
system("pause");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.