Learn first
Programs follow precise instructions
A program is a set of instructions. A variable stores a value. A condition chooses between paths. A loop repeats steps. Output is the result produced.
How to work it out Trace one instruction at a time. Keep a record of values and check exactly when a condition or repeated step is evaluated.
A separate example In a separate trace, start with n = 2, add 3, then double n. The two instructions happen in order: 5 is an intermediate value before the final result.
Define FUNCTION total(price, count): RETURN price * count; END for nonnegative integer inputs. Prices are whole fictional coin units. Keep calculation separate from SHOW. Each call returns its own result and changes no outside state.
Practice setup
The caller runs SET cost TO total(4, 3), followed by SHOW cost. The function total returns price × count. Distinguish returning a value, storing it, and displaying it.