c - time of the max and min temp

I need to make a program that calculates the maximum temperature, the minimum temperature, and the average temperature during the day. It is desired to have the knowledge at what time is the maximum and minimum temperature.

I'm fine with the first part, I'm just not sure what to do with the last part.

Output:
24 1

22 2

25 3

33 4

30 5

32 6

29 7

The left is the temp and the right the time as in 1:00 am.

The best I could do:
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
  #include <stdio.h>
#include <stdlib.h>

int hour, temp, average, sum, max, min;

void pro()
{
	sum=sum+temp;
	average=sum/7;
}

void iffy()
{
	if(temp<25)
	{
		min=temp;
	}
	if(temp>max)
	{
		max=temp;
	}
}

void time()
{
	//for the hours of the max and min temps
}

int main()
{
	FILE *fptr;

	if((fptr = fopen("temps and hours.txt", "r")) == NULL)
	{
		perror("Error! opening file");
		exit(1);
	}

	while(EOF != fscanf(fptr, "%d %d", &temp, &hour))
	{
		printf("%d  %d \n", temp, hour);
		pro();
		iffy();
	}
	
	
	printf("\nThe average temperature is: %d", average);
	printf("\nThe minimum temperature is: %d", min);
	printf("\nThe maximum temperature is: %d", max);
	printf("\nThe time for the maximum and minimum temperature is: %d  %d", //not sure);
}
Is this sample actually an example of what the input looks like (you wrote "Output")?
24	1
22	2
25	3
33	4
30	5
32	6
29	7


To remember a second bit of data like the hour, make second variable(s). Can probably do the logic in main and not necessarily outsource to a function, since your token variables, "temp" and "hour" are already conveniently there. Something like this:
1
2
3
4
5
6
7
8
9
10
if (temp < min_temp)
{
    min_temp = temp;
    min_hour = hour;
}
if (temp > max_temp)
{
    max_temp = temp;
    max_hour = hour;
}


Btw, the whole thing would be a lot simpler if you did it in C++ instead of C
Big Thanx!!
Topic archived. No new replies allowed.