Back to Challenge Set 10

Code Challenge: Hottest Hour

Difficulty  

divider

The Brief

What they asked for
I log a temperature reading every hour and I want to know
the highest one, without scrolling back through everything
I typed. Ask how many readings I have, then let me type them
in one at a time.

Write your requirements list before you write any code. Input, calculate, output, and anything you had to decide for yourself.


Notes

  • This is one pattern from Activity 1.20 — running max — used by itself. Step Tracker in this same set does three patterns at once; this challenge is just the one.
  • Winter readings can be negative. Starting your highest value at 0 will silently give a wrong answer whenever every real reading is below zero — the same trap Activity 1.20 warned about.
  • The safe starting value is the first reading itself, not 0 and not a guess. Read it before the loop starts, then loop over the rest.
  • Ask how many readings there are first — that number is your loop's bound.

Where to Start

Only one-star challenges have this section. If you already know how to begin, skip it — and when you move up to two stars, working out the order yourself is part of the job.

  1. Read how many readings there are, and parse it as an int.
  2. Read the first reading and store it as your starting highest value.
  3. Loop over the remaining readings. Inside the loop, compare each one to the highest value so far and replace it when a reading is bigger.
  4. Print the highest value after the loop, formatted with :F1. Test a set that is all negative before you submit.

Sample Output

Sample Output
How many readings? 4
Reading 1: -3.5
Reading 2: 12
Reading 3: 8.25
Reading 4: -10
Highest reading: 12.0

Verified in a real run — two of these four readings are negative, and the program still finds 12.0 as the highest.


Submit

Your requirements list and your program file, named cc-hottest-hour.

Commence Challenge