Week 3

Fuel Gauge

Turn a fraction into a percent, and ask again when the fraction is not usable.

You type

A fraction, such as two numbers with a slash.

The tool
A fraction, or another try Ask for a fraction If it is unusable, ask again again
What comes out

Empty, full, or a percentage. Bad fractions are asked again.

The question, more slowly

The question is: a fraction like a numerator, a slash, and a denominator. You print how full the tank is. Near empty and near full use the short words the spec gives. The middle is a percentage, rounded. If the fraction is not usable, ask again instead of crashing.

Unusable means you cannot read the numbers, the denominator is zero, or the numerator is larger than the denominator. Each of those is a different failure. Catching them and prompting again is the whole point of this week.

People round too early, or they treat a larger numerator as empty instead of asking again. Also check the exact cutoff for the short words in the spec. One percent and ninety-nine percent are the edges.

Before you code

Write three fractions: a normal one, one with zero on the bottom, and one where the top is larger than the bottom. Say what should happen for each. The spec decides.