Guide 1 of 7

Variables & Data Types

Variables are the memory boxes of your algorithms. Learn how to correctly declare, assign, and output data types in standard Cambridge, AQA, and OCR pseudocode.

⚡ Quick Review: Data Types

  • INTEGER: Whole numbers (e.g., 15, -3).
  • REAL: Decimal/fractional numbers (e.g., 3.14, -0.5).
  • STRING: Text enclosed in quotes (e.g., "Hello").
  • CHAR: A single character (e.g., 'A').
  • BOOLEAN: TRUE or FALSE.
  • Constant: A named memory location whose value cannot change while the program runs.

1. Identifier Naming Rules

An identifier is simply the name you give to a variable, constant, or array. Cambridge examiners will deduct marks if your identifiers are lazy (like naming a variable x instead of StudentScore).

Rule 1: Meaningful Names. Always use descriptive names. TaxRate is valid. T is invalid.
Rule 2: No Spaces. Variables cannot have spaces. Use CamelCase (e.g., HighScore) or snake_case (e.g., high_score).

2. Declaring and Assigning Variables

In standard pseudocode, you must DECLARE a variable's data type before you can use it. To assign a value to a variable, you do not use the equals sign (=). You must use the left-pointing arrow ().

Assignment Syntax
// Step 1: Declare the variable
DECLARE PlayerName : STRING
DECLARE PlayerScore : INTEGER

// Step 2: Assign a value using the arrow
PlayerName ← "Alex"
PlayerScore ← 0

// Step 3: Update the value
PlayerScore ← PlayerScore + 10

3. Constants

A Constant is a memory location whose value never changes during the execution of the program. You assign them using the CONSTANT keyword and an equals sign (=).

Constant Syntax
CONSTANT Pi = 3.14159
CONSTANT MaxUsers = 100

// This would cause an error because constants cannot change:
// Pi ← 4.0

4. INPUT and OUTPUT

To interact with a user, you use the OUTPUT command to display text on the screen, and the INPUT command to catch their keyboard response and save it into a variable.

Standard I/O
DECLARE Age : INTEGER

OUTPUT "Please enter your age:"
INPUT Age

// Combining text and variables
OUTPUT "Next year, you will be ", Age + 1

Interactive Exam Practice

Scenario: Write an algorithm that defines a CONSTANT for a 20% discount (0.20). Declare a variable for a price, ask the user to input a price, and then output the final discounted price.

Hover or tap the black box to reveal the examiner's solution. Click Run Code to test it instantly!

Tap to Reveal Answer
CONSTANT Discount = 0.20
DECLARE OriginalPrice : REAL
DECLARE FinalPrice : REAL

OUTPUT "Enter the original price:"
INPUT OriginalPrice

FinalPrice ← OriginalPrice - (OriginalPrice * Discount)

OUTPUT "The discounted price is: $", FinalPrice