1.) If the dimension for array temperature is 7 rows and 2 columns, how many instances the inner loop iterates? How about the outer loop? 2.) How was it made it possible for the program to determine the average high temperature and average low temperature?
*Try to run the program in c++ then answer the questions below*
PROGRAM:
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int temp [7][2];
int high_temp, low_temp;
double total_high = 0.0, total_low = 0.0, avg_high = 0.0, avg_low = 0.0;
cout << "\t===========================";
cout << "\n\tDay Highest Lowest\n";
cout << "\t===========================";
cout << endl <<endl;
for(int row = 0; row < 7; row += 1)
{
for (int col = 0; col < 2; col += 1)
{
if (col == 0)
{
cout << "\t " << row +1 << "\t";
cin >> temp [row][col];
}
else
{
cin >> temp [row][col];
}
}
}
cout << "\n\t===========================";
cout << endl << "\t";
high_temp = temp [0][0];
low_temp = temp [0][1];
for (int col = 0; col < 2; col ++)
{
for (int row = 0; row < 7; row ++)
{
if ((col == 0) && (temp [row][col] > high_temp))
high_temp = temp [row][col];
if ((col == 1) && (temp [row][col] <low_temp))
low_temp = temp [row][col];
if (col == 0)
total_high = total_high + temp[row][col];
if (col == 1)
total_low = total_low + temp[row][col];
}
if (col == 0)
{
avg_high = total_high / 7.0;
cout <<fixed;
cout <<setprecision (2);
cout << "\n\tThe average high temperature: "
<< avg_high <<endl;
}
else
{
avg_low = total_low / 7.0;
cout <<fixed;
cout <<setprecision (2);
cout << "\n\tThe average high temperature: "
<< avg_low <<endl <<endl;
}
}
return 0;
}
QUESTIONS:
1.) If the dimension for array temperature is 7 rows and 2 columns, how many instances the inner loop iterates? How about the outer loop?
2.) How was it made it possible for the program to determine the average high temperature and average low temperature?
Trending now
This is a popular solution!
Step by step
Solved in 2 steps