I'm not sure what's wrong with my functions, need assistance.

I have three functions in this code. One to return the average temperature, one to return the highest value, and another to return the lowest value. Here's my code. Any assistance would be greatly appreciated!


#include <iostream>
using namespace std;
float temptotal = 0;
float averagetemp = 0;
float max = -9999999999999;
float min = 9999999999999;
float days = 0;
float temperatures[50];
void average();
void highest();
void lowest();
int main()
{
cout << "Enter the number of days: ";
cin >> days;
if (days > 50)
{
cout << "You may only enter temperatures for 50 days." << endl;
return 0;
}
void average();
void highest();
void lowest();
for (int i = 1; i <= days; i++)
{
void average(float temperatures[50])
{
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()
{
if (temperatures[i] > max)
max = temperatures[i];
cout << "The highest temperature is: " << max << endl;
}
void lowest()
{
if (temperatures[i] < min)
min = temperatures[i];
cout << "The lowest temperature is: " << min << endl;
}
}
return 0;
}
initialisation of max and min is not working that way

float is 4byte = 32bit = 2^32 = 4294967296
your numbers are too long
Functions need to be defined outside of main. If you're supposed to be returning values from the functions, the return type can't be void.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//function protoypes
void average();
void highest();
void lowest();

//main function - functions are called here
average();
highest();
lowest();
//end main

//function definitions
void average()
{
//function code
}
void highest()
{
//function code
}
void lowest()
{
//function code
}
Topic archived. No new replies allowed.