Unable to open this exercise
A variable stores a value that may change. A constant names a value that does not change while the program runs. Naming a fixed price or limit makes its purpose clear and avoids repeating unexplained numbers.
CONSTANT TicketPrice = 7
DECLARE Tickets : INTEGER
INPUT Tickets
OUTPUT TicketPrice * Tickets
Worked example
For three tickets, the expression is 7 × 3 = 21. The number of tickets is input and may differ next time; TicketPrice stays fixed in this program. Changing the price in one declaration is easier to maintain than finding many occurrences of 7.
Do not write INPUT TicketPrice: input belongs in a variable. Scope—where an identifier can be used—is taught with procedures and functions, after you have seen those constructs.
AI Socratic Tutor
Need guidance? Ask a question or use the hint below.
AI Socratic Tutor is an All-Access Benefit
Unlock step-by-step Socratic hints, algorithm trace table walkthroughs, and error diagnostics for every Cambridge exercise.
You're chatting with an AI tutor, not a person. AI can make mistakes, so double-check its answers.
Application: Check the reasoning
Application: Check the reasoning
- Identifier whose value stays fixed during execution: [Space 1]
- Should changing user input be stored in a constant or variable? [Space 2]
- Does a named constant help explain an otherwise unexplained number: yes or no? [Space 3]
Interactive exercises for Module 2 and beyond require an active plan.