BETA Try the new lesson view
Code

The warmest day and searching

Two new functions: one finds the largest value, the other a value you ask for.

The warmest day

int warmest(const int t[], int n)

It returns not a temperature but an index: from it main learns both the day (w + 1) and the temperature (temperatures[w]). At the start the first day counts as the best (best = 0), and the loop from i = 1 compares the rest with it. When several days are equally warm, the first one stays, because it changes only on >, not >=.

int find(const int t[], int n, int value)

It is as in the pseudocode: return i; on a match ends both the function and the loop at once. After the loop, return -1;: the value wasn't there.

At the end, main asks which temperature to look for and prints one of two sentences, depending on what find returns. The check pos == -1 is a must: temperatures[-1] would be out of bounds.

Run it

The same week, and you look for 5:

...
Temperatures: 3 -2 5 8 -1 4 6
Average: 3.29
Warmest: day 4, 8 C
Which temperature to look for? 5
5 C was first on day 3.

Run it again and look for -5:

-5 C was not on any day.

Commit: Find warmest day.