#include <iostream>
usingnamespace std;
float temptotal;
float averagetemp = 0;
float temperatures[50];
void average();
void highest();
void lowest();
int main()
{
average();
highest();
lowest();
}
void average()
{
float days = 0;
cout << "Enter the number of days: ";
cin >> days;
if (days > 50)
{
cout << "You may only enter temperatures for 50 days." << endl;
}
for (int i = 1; i <= days; i++)
{
cout << "Enter the temperature for day number " << i << ": ";
cin >> temperatures[i];
temptotal += temperatures[i];
averagetemp = (temptotal / days);
cout << "The average temperature is: " << averagetemp << endl;
}
}
void highest()
{
float max = -9999999999999;
if (temperatures[50] > max)
max = temperatures[50];
cout << "The highest temperature is: " << max << endl;
}
void lowest()
{
float min = 9999999999999;
if (temperatures[50] < min)
min = temperatures[50];
cout << "The lowest temperature is: " << min << endl;
}
temptotal should be initialized if you're going to use it to accumulate a total.
line 22 - you output a message if they input an invalid number, but still go ahead with the input. This could end up trying to access array elements out of range.
line 24 - array elements run from 0 to the size of the array minus 1, so 0 to 49, not 1 to 50
line 29-30 Do you mean to calculate an average just once or after each entry of temperature?
line 36, line 44 - you're checking against an element that doesn't exist. Seems like you'd want to use another for loop here to go through all the daily temps entered to find the smallest or largest.