Back to Challenge Set 4

Code Challenge: Oxygen Alarm

Difficulty  

divider

The Brief

What they asked for
I monitor life support for the sim lab. Our rule is simple:
oxygen below 15 percent means a warning, everything else is
nominal. Type the reading in and put the message on screen so
I don't have to say it out loud every single time.

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


Notes

  • Two outcomes, so this is one if with one else. It does not need a chain.
  • Oxygen readings are not whole numbers. Pick your parse accordingly.
  • The brief already gives you the number. This one has no calculation inside the decision — the whole job is picking the right comparison.
  • A reading of exactly 15 percent has to get one answer. The brief says “below 15 percent,” which tells you which side 15 itself falls on.

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. Get the oxygen reading and parse it with double.Parse.
  2. Write the if for the alert case first, using the comparison the brief tells you.
  3. Add the else for everything else.
  4. Test 12, 15, and 18 before you submit — those three are where a boundary mistake shows up.

Sample Output

Sample Output
Oxygen level (%): 12
ALERT: oxygen below 15%. Check the scrubber or switch to a backup supply.

A reading of 18 percent should print nominal, not an alert. Test 12, 15, and 18 before you submit — 15 exactly still has to be nominal, since the brief's boundary is “below” 15, not “at or below.”


Submit

Your requirements list and your program file, named cc-oxygen-alarm.

Commence Challenge