Published by Patrick Mutisya · 14 days ago
Write pseudocode statements for the declaration and initialisation of constants.
In the Cambridge A‑Level pseudocode, a constant is declared with the CONST keyword followed by the identifier, an optional type, and the value it is to hold.
| Constant Name | Type (optional) | Value | Pseudocode Statement |
|---|---|---|---|
| MAX_STUDENTS | INTEGER | 30 | CONST MAX_STUDENTS : INTEGER ← 30 |
| PI | REAL | 3.14159 | CONST PI : REAL ← 3.14159 |
| WELCOME_MSG | STRING | "Welcome to the system" | CONST WELCOME_MSG : STRING ← "Welcome to the system" |
| GRA \cdot ITY | REAL | 9.81 | CONST GRA \cdot ITY : REAL ← 9.81 |
CONST DAYSINWEEK : INTEGER ← 7
CONST TAX_RATE : REAL ← 0.20
To calculate the circumference of a circle, you might write:
CONST PI : REAL ← 3.14159
circumference ← 2 * PI * radius
where the value of PI cannot be changed later in the program.
The value of a constant can be shown mathematically, for example the constant π:
\$\pi = 3.14159\$