In: Computer Science
In visual Studio C++ Create a program that uses a for loop to input the high temperature, and low temperature for each day of the week.
The high and low will be placed into two elements of the array.
For each loop the high and low will be placed into the next set of elements of the array.
After the temps for all seven days have been entered into the array, a for loop will be used to pull out the high and low temps and total them.
After all temps have been totaled, the average high and low will be calculated.
The output will display the following; The total high temps is "total high" The total low temps is "total low" The average high temps is "average high" The average low temps is "average low"
Code
#include<iostream>
#include<iomanip>
using namespace std;
const int DAYS_OF_WEEK=7;
int main()
{
double temp[DAYS_OF_WEEK][2];
double total_high=0,total_low=0;
double average_high,average_low;
for(int i=0;i<DAYS_OF_WEEK;i++)
{
cout<<"Enter the high
temprature for day "<<(i+1)<<" : ";
cin>>temp[i][0];
cout<<"Enter the low
temprature for day "<<(i+1)<<" : ";
cin>>temp[i][1];
cout<<endl;
}
for(int i=0;i<DAYS_OF_WEEK;i++)
{
total_high+=temp[i][0];
total_low+=temp[i][1];
}
average_high=total_high/DAYS_OF_WEEK;
average_low=total_low/DAYS_OF_WEEK;
cout<<fixed<<setprecision(2);
cout<<"\nThe total high temps is
"<<total_high<<endl;
cout<<"The total low temps is
"<<total_low<<endl;
cout<<"The average high temps is
"<<average_high<<endl;
cout<<"The average low temps is
"<<average_low<<endl;
return 1;
}
output
If you have any query regarding the code please ask me in the
comment i am here for help you. Please do not direct thumbs down
just ask if you have any query. And if you like my work then please
appreciates with up vote. Thank You.