Answer to Question #46330 in C++ for trust

Question #46330
write a program that will accept temperatures for the month of September. the program should store the values in an array. the program should calculate and displays the average temperature and also displays the highest and lowest temperature with the their date as recorded
1
Expert's answer
2015-06-04T03:29:23-0400
#include <iostream>
#include <cstdlib>
using namespace std;
double Average(double temperature[], int size);
int Lowest(double temperature[], double& lowest, int size);
int Highest(double temperature[], double& highest, int size);
int main() {
double temperature[30];
double lowest = 0.0, highest = 0.0;
for (int i = 0; i < 30; i++) {
cout<<"Enter temperature for "<<i+1<<" September : ";
cin>>temperature[i];
}
cout<<"\nAverage temperature : "<<Average(temperature, 30)<<endl;
cout<<"Highest temperature found on "<<Highest(temperature, highest, 30) + 1;
cout<<" september and value is  "<<highest<<endl;
cout<<"Lowest temperature found on "<<Lowest(temperature, lowest, 30) + 1;
cout<<" september and value is  "<<lowest<<endl;
system("pause");
return 0;
}
double Average(double temperature[], int size) {
double total = 0;
for(int i = 0; i < size; i++)
total += temperature[i];
return total/size;
}
int Lowest(double temperature[], double& lowest, int size) {
lowest = temperature[0];
for(int i = 0; i < size; i++)
if (temperature[i] < lowest)
lowest = temperature[i];
for(int i = 0; i < size; i++)
if (temperature[i] == lowest)
return i;
}
int Highest(double temperature[], double& highest, int size) {
    highest = temperature[0];
for(int i = 0; i < size; i++)
if (temperature[i] > highest)
highest = temperature[i];
for(int i = 0; i < size; i++)
if (temperature[i] == highest)
return i;
}


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS