60.2k views
1 vote
Declare a seven-row, two-column int array named temperatures. The program should prompt the user to enter the highest and lowest temperatures for seven days. Store the highest temp in the first column and the lowest in the second column. The program should display the average high and average low temperature. Display the average temperatures with one decimal place.

User Kasper
by
3.4k points

1 Answer

3 votes

Answer:

Following are the code to the given question:

#include<iostream>//header file

#include<iomanip>//header file

using namespace std;

int main()//main method

{

double temperatures[7][2];//defining a double array temperatures

double lowAvg=0, highAvg=0;//defining a double variable

for(int i = 0;i<7;i++)//defining loop to input the value

{

cout<<"Enter day "<<(i+1)<<" highest temperatures: ";//print message

cin>>temperatures[i][0];//input highest temperatures value

cout<<"Enter day "<<(i+1)<<" lowest temperatures: ";//print message

cin>>temperatures[i][1];//input lowest temperatures value

}

cout << fixed << setprecision(1);//using the setprecision method

for(int i = 0;i<7;i++)//defining loop to calculating the Average of the

{

highAvg += temperatures[i][0];//holding highest value

lowAvg += temperatures[i][1];//holding lowAvg value

}

cout<<"Average high temperature = "<<highAvg/7<<endl;//calculate amd print highest temperature Average

cout<<"Average low temperature = "<<lowAvg/7<<endl;//calculate amd print lowest temperature Average

return 0;

}

Output:

Please find the attached file.

Step-by-step explanation:

  • In this code, a 2D array "temperatures" and two-variable "highAvg, lowAvg" as double is declared, that uses the two for loops.
  • In the first loop, it uses an array to input the value from the user-end.
  • In the second loop, it uses the double variable that calculates the average value of the temperature.
Declare a seven-row, two-column int array named temperatures. The program should prompt-example-1
User Anake
by
3.5k points