Free practice · ordering · medium

Practice

Order a safe conversion workflow

Arrange a safe workflow for converting a quantity entered as text.

Typed expression trace

Every value has a type before an operator uses it

Source
Raw value and its current type
Contract
Allowed type, format, and range
Conversion
Explicit and failure-aware
Expression
Operators applied by precedence
Evidence
Resulting value and type

Track the source value, current type, conversion boundary, evaluation order, and resulting type instead of relying on how a value looks.

Arrange in the correct order
  1. 1. Use the converted quantity in the calculation
  2. 2. Convert it to int
  3. 3. Confirm it represents an allowed whole number
  4. 4. Read the raw quantity text