Chapter 7: money, typed
Chapter 7's Receipt adds up a shopping basket in pounds: prices written with the #GBP suffix, multiplied by whole quantities, summed and printed in en_GB format. The IDE writes the program's shell; the amounts are yours to type. To play it in the IDE: Help > Lessons > Getting Started with EK9…, or ek9 -ide -lesson book-receipt.
What you'll build
The lesson builds this program from a file holding only its module line - the finished file, as the book prints it.
#!ek9 defines module book.receipt defines program Receipt() stdout <- Stdout() enGB <- Locale("en_GB") applePrice <- 0.35#GBP breadPrice <- 1.10#GBP milkPrice <- 0.85#GBP apples <- 6 loaves <- 2 bottles <- 1 appleLine <- applePrice * apples breadLine <- breadPrice * loaves milkLine <- milkPrice * bottles total <- appleLine + breadLine + milkLine stdout.println(`Apples x${apples} ${enGB.format(appleLine)}`) stdout.println(`Bread x${loaves} ${enGB.format(breadLine)}`) stdout.println(`Milk x${bottles} ${enGB.format(milkLine)}`) stdout.println(`Total ${enGB.format(total)}`)
Step 1: The program's shell
Choose Code > New Construct > Program…
Receipt is the program's name. Type it and choose Preview.
The preview shows Receipt about to be written. Choose Apply.
The tool leaves no blank line before the program: select the Receipt() line and, above it, type the one the book opens with. Saves when typed.
Step 2: The body, typed
Select the stub, from ready <- true down to its //AI line, and type the body exactly as the chapter shows it. Saves when typed.
Step 3: Run it
Choose Run > Run Program…
The project's only program is already chosen. Choose Run.
Apples x6 £2.10, Bread x2 £2.20, Milk x1 £0.85, Total £5.15. Choose Close.
The result
Receipt.ek9 now reads exactly as chapter 7 of Getting Started with EK9 shows it: Money times an Integer is Money, Money plus Money is Money, and the Locale formats each as pounds.
Where this lesson comes from
- For AI assistants - the MCP tool
ek9_add_program.
In the EK9 reference: EK9 Basics








