Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Temperature Converter

Generate it:

lumen --examples temperature
temp = 0
result = 0

routine c2f
result = temp * 9 / 5 + 32
endroutine

routine f2c
result = temp - 32
result = result * 5 / 9
endroutine

routine ask
print 'Temparature: '
endroutine

routine show
print 'Result: '
println result
endroutine

println '1. C to F'
println '2. F to C'
print 'Select mode '
mode = 0
inputInt &mode
if mode == 1
call ask
inputInt &temp
call c2f
call show
else
if mode == 2
call ask
inputInt &temp
call f2c
call show
else
println 'Incorrect mode'
endif
endif

The most feature-complete example in the box. It combines:

  • Four routines (c2f, f2c, ask, show) that communicate purely through the shared variables temp and result — see Routines for why this pattern exists.
  • Nested if/else to build a three-way menu (mode == 1, mode == 2, anything else) — see Conditionals.
  • inputInt used twice: once for the menu selection, once for the temperature value itself.

It’s a good template to copy from when you want a small menu-driven Lumen program with reusable logic.