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

Here is my code, //intermediate22.cpp #include<iostream> #include<iomanip> using

ID: 3809922 • Letter: H

Question

Here is my code,

//intermediate22.cpp
#include<iostream>
#include<iomanip>

using namespace std;
int main()
{
   //declaration of array
   int temperatures[7][2] = { 0 };
   //declare the local variables
   double avgHigh = 0.0;
   double avgLow = 0.0;
   int total = 0;
   int high = 0;
   int low = 0;
   //receive input from user
   cout << "Enter highest and lowest temperatures for 7 days" << endl;
   for (int row = 0; row < 7; row += 1)
   {
       for (int col = 0; col < 2; col += 1)
       {
           if (col == 0)
           {
               cout << "Day" << row + 1
                   << "high temp:";
               cin >> temperatures[row][col];
           }
           else
           {
               cout << "Day" << row + 1
                   << "low temp:";
               cin >> temperatures[row][col];
           }//end if
       }//end for
       cout << endl;
   }//end for
   //calculate and display the average of high //temperature
   //and average of lowest temperature along with highest
   //temperature and lowest temperature
   high = temperatures[0][0];
   low = temperatures[0][1];
   for (int col = 0; col < 2; col += 1)
   {
       for (int row = 0; row < 7; row += 1)
       {
           total += temperatures[row][col];
           if (col == 0)
           {
               if (temperatures[row][col] > high)
                   high = temperatures[row][col];
           }
           else
           {
               if (temperatures[row][col] < low)
                   low = temperatures[row][col];
           }//end if
       }//end for
       if (col == 0)
       {
           avgHigh = total / 7.0;
           cout << fixed << setprecision(1);
           cout << "Average of the Highest temperature is:" << avgHigh << endl;
           cout << "Highest temperature is" << high <
       }
       else
       {
           avgLow = total / 7.0;
           cout << fixed << setprecision(1);
           cout << "Average of the lowest temperature is:" <
               cout << "Lowest temperature is" << low << endl;

       }// end if
       total = 0;
   }//end for
   system("pause");
   return 0;
} //end of main function

EDIATE 23. If necessary, create a new project named Intermediate23 Project and save the in Cpp8lChap12 folder. Also create a new source file named Intermediate23 Declare seven-row, two-column int array named temperatures. The program should the prompt the user to enter the highest and lowest temperatures for seven days. Store highest temperatures in the first column in the array. Store the lowest temperatures in the second The program should display the average high temperature and the column average low temperature. Display the average temperatures with one decimal place. Save and then run the program. Test the program using the data shown in Figure 1 Lowest Highest Day 67 95 54 98 70 86 56 99 34 75

Explanation / Answer

Hi

I have fixed the issue and highlighted the code changes below

#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
//declaration of array
int temperatures[7][2] = { 0 };
//declare the local variables
double avgHigh = 0.0;
double avgLow = 0.0;
int total = 0;
int high = 0;
int low = 0;
//receive input from user
cout << "Enter highest and lowest temperatures for 7 days" << endl;
for (int row = 0; row < 7; row += 1)
{
for (int col = 0; col < 2; col += 1)
{
if (col == 0)
{
cout << "Day" << row + 1
<< "high temp:";
cin >> temperatures[row][col];
}
else
{
cout << "Day" << row + 1
<< "low temp:";
cin >> temperatures[row][col];
}//end if
}//end for
cout << endl;
}//end for
//calculate and display the average of high //temperature
//and average of lowest temperature along with highest
//temperature and lowest temperature
high = temperatures[0][0];
low = temperatures[0][1];
for (int col = 0; col < 2; col += 1)
{
for (int row = 0; row < 7; row += 1)
{
total += temperatures[row][col];
if (col == 0)
{
if (temperatures[row][col] > high)
high = temperatures[row][col];
}
else
{
if (temperatures[row][col] < low)
low = temperatures[row][col];
}//end if
}//end for
if (col == 0)
{
avgHigh = total / 7.0;
cout << fixed << setprecision(1);
cout << "Average of the Highest temperature is:" << avgHigh << endl;
cout << "Highest temperature is" << high <<endl;
}
else
{
avgLow = total / 7.0;
cout << fixed << setprecision(1);
cout << "Average of the lowest temperature is:" <
cout << "Lowest temperature is" << low << endl;
}// end if
total = 0;
}//end for
// system("pause");
return 0;
} //end of main function

Output:

sh-4.2$ g++ -o main *.cpp                                                                                                                                                                                                                                                

sh-4.2$ main                                                                                                                                                                                                                                                             

Enter highest and lowest temperatures for 7 days                                                                                                                                                                                                                         

Day1high temp:7                                                                                                                                                                                                                                                          

Day1low temp:1                                                                                                                                                                                                                                                           

                                                                                                                                                                                                                                                                         

Day2high temp:23                                                                                                                                                                                                                                                         

Day2low temp:21                                                                                                                                                                                                                                                          

                                                                                                                                                                                                                                                                         

Day3high temp:34                                                                                                                                                                                                                                                         

Day3low temp:33                                                                                                                                                                                                                                                          

                                                                                                                                                                                                                                                                         

Day4high temp:44                                                                                                                                                                                                                                                         

Day4low temp:41                                                                                                                                                                                                                                                          

                                                                                                                                                                                                                                                                         

Day5high temp:22                                                                                                                                                                                                                                                         

Day5low temp:21                                                                                                                                                                                                                                                          

                                                                                                                                                                                                                                                                         

Day6high temp:77                                                                                                                                                                                                                                                         

Day6low temp:66                                                                                                                                                                                                                                                          

                                                                                                                                                                                                                                                                         

Day7high temp:44                                                                                                                                                                                                                                                         

Day7low temp:22                                                                                                                                                                                                                                                          

                                                                                                                                                                                                                                                                         

Average of the Highest temperature is:35.9                                                                                                                                                                                                                               

Highest temperature is 77                                                                                                                                                                                                                                                 

Average of the lowest temperature is:Lowest temperature is 1

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