Write a program that use a two-dimensional array to store the highest and lowest
ID: 3935403 • Letter: W
Question
Explanation / Answer
#include <iostream>
using namespace std;
void getData(double temp[12][2]) //get mimimum and maximum temperature for 12 months
{
int i,j;
cout<<" Enter the minimum and maximum temperature for 12 months";
for(i=0;i<12;i++)
for(j=0;j<2;j++)
cin>>temp[i][j];
}
void averageHigh(double temp[12][2]) // calculate avergae high for 12 months
{
int i ,j;
j=1;
double avgHigh=0;
for(i=0;i<12;i++)
avgHigh =avgHigh + temp[i][j];
cout<<" Average High Temperature :"<<avgHigh/10;
}
void averageLow(double temp[12][2]) // calculate average low for 12 months
{
int i ,j;
j=0;
double avgLow=0;
for(i=0;i<12;i++)
avgLow =avgLow + temp[i][j];
cout<<" Average Low Temperature :"<<avgLow/10;
}
void indexHighTemp(double temp[12][2]) //find the month for highestest temperature
{
double highTemp=0;
int month,i,j=1;
for(i=0;i<12;i++)
{
if(temp[i][j] > highTemp)
{
highTemp =temp[i][j];
month =i;
}
}
cout<<" The highest Temperature in the year is "<<highTemp<< " degrees celcius in month "<<month+1;
}
void indexLowTemp(double temp[12][2]) //find the month for low temperature
{
double lowTemp=99;
int month,i,j=0;
for(i=0;i<12;i++)
{
if(temp[i][j] < lowTemp)
{
lowTemp =temp[i][j];
month =i;
}
}
cout<<" The lowest Temperature in the year is "<<lowTemp<<" degrees celcius in month "<<month+1;
}
int main()
{
double temp[12][2];
getData(temp);
averageHigh(temp);
averageLow(temp);
indexHighTemp(temp);
indexLowTemp(temp);
return 0;
}
output:
Success time: 0 memory: 3472 signal:0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.