Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Write a program using structures to store the following weather information:

ID: 3683447 • Letter: C

Question

C++

Write a program using structures to store the following weather information:

Total Rainfall

High Temperature

Low Temperature

Average Temperature

The program should have an array of 12 structures to hold the weather data (the average temperature should be calculated). Once the data for all the months is entered, the program should calculate and display the average monthly rainfall, total rainfall for the year, highest and lowest temps for the year (and the months they happen in) and the average of all the months average temperatures.

Input temps should be between -100 and +140 and and total rainfall must not be less than 0

Explanation / Answer

#include<iostream>

using namespace std;

struct weatherinfo
{
double totalRain;
double highTemp;
double lowTemp;
double avgTemp;
};
  
int main( )
{

int n=12;
string months[]={"January","February","March","April","May","June","July","August","September","October","November","December"};
double totRain=0,avgRain=0,avgTemp=0,htemp,ltemp,atemp,rainfall;
double maxTemp=0,minTemp=0,totTemp=0;
int hiMonthCount=0,lowMonthCount=0;
weatherinfo warray[n];

for(int i=0;i<12;i++)
{
   cout<<"==============Weather information in "<< months[i] <<"====================";
  
       while(true)
       {
       cout<<" Enter the Total Rainfall in the Month "<< months[i] <<" is :";
cin>>rainfall;
if(rainfall>0)
{
   cin>>warray[i].totalRain;
   }
       else
       {
          System.out.println("** The total rainfall must not be less than 0 **");
       continue;
       }
       }

       while(true)
       {
       cout<<" Enter The High Temperature in the Month "<< months[i] <<" is :";
cin>>htemp;
if(htemp>=-100 && htemp>=+140 )
{
       cin>>warray[i].highTemp;
       }
       else
       {
          System.out.println("** Temperature should be between -100 and +140 **");
       continue;
       }
       }
while(true)
{
cout<<" Enter The Low Temperature in the Month "<< months[i] <<" is :";
cin>>ltemp;
if(ltemp>=-100 && ltemp>=+140 )
{
    cin>>warray[i].lowTemp;
       }
       else
       {
       continue;
       }  
       }
  
while(true)
{
   cout<<" Enter The Average Temperature in the Month "<< months[i] <<" is :";
cin>>atemp;
if(atemp>=-100 && atemp>=+140 )
{
    cin>>warray[i].avgTemp;
       }
          else
       {
       continue;
       }
       }

       totRain=totRain+warray[i].totalRain;

}
maxTemp=warray[0].highTemp;
minTemp=warray[0].lowTemp;   
for(int i=0;i<12;i++)
{
   if(maxTemp<warray[i].highTemp)
   {
       maxTemp=warray[i].highTemp;
       hiMonthCount++;
           }
           if(minTemp>warray[i].lowTemp)
           {
           minTemp=warray[i].lowTemp;
           lowMonthCount++;
           }
           totTemp=totTemp+((warray[i].highTemp+warray[i].lowTemp)/2);
       }
       avgRain=totRain/12;
       avgTemp=totTemp/12;
cout<<" The Average Monthly Rainfall is:"<<avgRain ;
cout<<" The Total Rainfall for the year is:"<<totRain ;
cout<<" The Highest Temperature is Recorded in the month of "<< months[hiMonthCount] <<" is:"<<maxTemp ;
cout<<" The Lowest Temperature is Recorded in the month of "<< months[lowMonthCount] <<" is:"<<minTemp ;
       cout<<" The Average Temperature of the total year is:"<<avgTemp ;
return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote