Constants, Scope & Value Protection

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

All-Access
Sign in or create an account. AI Tutor is an All-Access benefit.
Sign Up

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.

Independent Practice: A fixed ticket price

+30 XP

Each ticket costs 7 units. Read the integer number of tickets and output the total price. Represent the fixed price with a named constant.

Write a complete program. Read inputs in the stated order. Output only the requested results, one per line, without input prompts. Test with your own values before submitting.

solution.pseudo
All-Access Required

Interactive exercises for Module 2 and beyond require an active plan.

○ Three tickets
○ No tickets
○ Ten tickets