comparing number in an array

ok so I have a filled array and wish to compare the numbers within the array to determine the Highest and the Lowest number
now I know I need a for loop for this but am unsure how to implemented this can someone point me in the right direction?
Post your code so far.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
void get_hrTmps (int hr_tmps[],int tmp_num); //function for user input
double ComputeAverageTemp(int hr_tmps[],int tmp_num);//add the individual array element and then avereage them
void DisplayTemperatures(int hr_tmps[], int temp_num);

#include <iostream>// for cin,cout
using namespace std;

int main ()
{
	const int tmp_num = 24 ;//constant for 24 hours
	int hr_tmps[tmp_num];//array to hold the hours


	get_hrTmps(hr_tmps,tmp_num);//function call fdor input

	ComputeAverageTemp(hr_tmps,tmp_num);//function call to add the individual array element and then avereage them
	
	DisplayTemperatures( hr_tmps,  tmp_num);


	return 0;
}

void get_hrTmps (int hr_tmps[],int tmp_num)//input function
{
    cout<<"please enter a temp for each hour of the day\n please use only #'s between -15 and a 130\n";

    for (int x=0; x<tmp_num; x++)

	cin>>hr_tmps[x];

}


double ComputeAverageTemp(int hr_tmps[],int tmp_num)//calculation function
{
	int total=0;
	double average;

	for (int x=0;x<tmp_num;x++)

		total=total+hr_tmps[x];
	average=total/24;
	return average;
}


void DisplayTemperatures(int hr_tmps[], int tmp_num )//output function
{
	
	for (int x=0;x<tmp_num;x++)

		cout<<hr_tmps[0-23]<<endl;
}


this is the code thus far . there are errors in this version but have been corrected (this is the only access i have to the code at the moment((at work))). I haven't written the function for the comparison of the highest and lowest yet as I have no clue yet .what i want to do is compare the array for the highest and lowest number.
Last edited on
Topic archived. No new replies allowed.