Weather Calculator Program in C ++
A weather analysis program uses the following array to store the temperature for each hour of the day on each day of a week.
Each row represents a day (0 = Sunday, 1 = Monday, etc.) and each column represent sa time (0 = midnight, 1 = 1 a.m., … , 12 = noon, 13 = 1 p.m., etc.).
- A) Write code to find Tuesday’s average temperature.
- B) Write code to find the average weekly noon temperature.
/* tuesday = 2, noon = 12; */
cout<<“enter the two dimensional array with rows as days of the week and time as columns”;
} /* 00 will show position sunday and 12 noon
01 ->sunday 1 am
02->sunday 2 am
temp->monday 1 am
temp->tuesday 2 am
temp->tuesday 3 am
similary we can find for all tuesdays in the array */
int tuesday_sum = 0, tuesday_averagetemp;
int noon_total=0, noon_average;
for (int i = 0; i<24; i++)
tuesday_sum += temp[i]; /* we have used 2 as it signifies tuesday */
tuesday_averagetemp = tuesday_total/24;
cout<<“Average temperature for tuesday is: “<<tuesday_averagetemp<<endl;
/* calculate average weekly noon temperature.Here we will fix the j variable as 12 as it detemines the time at 12 pm(noon) and we will increment i for days sunday to saturday from i=0 to i=6 */
for (int i=0; i<7; i++)
noon_total += temp[i];
noon_average = noon_total/7;
cout<<“” the average weekly noon temperature is “;