1. Variables and constants
A variable can be changed during the execution of a program. A constant cannot be changed during the execution of a program.
Declare each one before it is used, with a meaningful name that has no spaces. Give a variable its starting value before you use it.
``` DECLARE Total : INTEGER CONSTANT MaxScore ← 50 Total ← 0 ```
Use `←` to assign a value. Do not use `=`, which is a relational operator.
Examiner insight
Worked example 13 marks
A program calculates the cost of tickets for a school trip. Every ticket costs 12. The number of tickets bought is input each time the program runs.
Identify one constant and one variable for this program, with a reason for each. Write the statement that declares the variable.
- 1
Constant: `TicketPrice`, because its value never changes while the program runs [1]
- 2
Variable: `NumberOfTickets`, because it is input and so changes each time [1]
- 3
Declaration: `DECLARE NumberOfTickets : INTEGER` [1]