I need to figure out how to get the min/max in this array. I heard that it can be done using the algorithm library. we have yet to learn that. any help would be appreciated.
#ifndef Lab4_h
#define Lab4_h
void GetTemperatures (int Temperatures[], int NumTemperatures);
double ComputeAverageTemp (int Temperatures[], int NumTemperatures);
void DisplayTemperatures (int Temperatures[], int NumTemperatures, double AverageTemp);
#endif
#include <iostream>
#include <algorithm>
using namespace std;
#include "nlab4.h"
int main ()
{
const int NumTemperatures = 23;
int HourlyTemperatures[NumTemperatures] = {0};
double AverageTemp = 0.0;
int min=0, max=0;
GetTemperatures (HourlyTemperatures, NumTemperatures);
AverageTemp = ComputeAverageTemp (HourlyTemperatures, NumTemperatures);
DisplayTemperatures (HourlyTemperatures, NumTemperatures, AverageTemp);
return 0;
}
void GetTemperatures (int Temperatures[], int NumTemperatures)
{
int Count = 0;
int CurrentTemp = 0;
int TimerCount = 0;
while (Count < 24)
{
if (CurrentTemp > -50 && CurrentTemp < 131)
{
cout<<"Temperature at "<<TimerCount++<<":00? ";
cin>>CurrentTemp;
Temperatures[Count++] = CurrentTemp;
}
else
{
cout<< "Incorrect temperature input \n";
cout<<"Please input temperature between -50 an 130 degrees \n";
cout<<"Re-input temperature: \n";
cin>>CurrentTemp;
}
}
}
double ComputeAverageTemp (int Temperatures[], int NumTemperatures)
{
double AverageTemp = 0.0;
int Count = 0;
int Sum = 0;
for (Count = 0; Count < 24; Count++)
{
Sum = Sum + Temperatures[Count];
}
AverageTemp = Sum / NumTemperatures;
return AverageTemp;
}
void DisplayTemperatures (int Temperatures[], int NumTemperatures, double AverageTemp)
{
int Count = 0;
cout << "*******************************\n";
cout << "Hour\t\tTemperature\n";
while (Count < 24)
{
cout << "0" << Count << ":00\t\t" << Temperatures[Count++] << endl;
}
cout << "*******************************\n";
cout << "High Temp: \t\t\n";
cout << "Low Temp: \t\t\n";
cout << "Average Temp:\t" << AverageTemp << endl;
cout << "*******************************\n";
}