DECLARE a variable (7a)

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

DECLARE a variable (7a)

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which line correctly declares a whole-number variable called Counter?
A DECLARE Counter : INTEGER
B DECLARE INTEGER : Counter
2. Which line declares a variable to hold a price that can have pence, such as 12.50?
A DECLARE TotalToPay : INTEGER
B DECLARE TotalToPay : REAL
3. Which line declares a variable that stores only TRUE or FALSE?
A DECLARE GameOver : STRING
B DECLARE GameOver : BOOLEAN
4. What does the DECLARE statement do?
A It creates a variable with a name and a data type
B It gives a variable its first value from the user
5. Which is the correct way to declare two variables, Score and Lives, both INTEGER?
A DECLARE Score : INTEGER DECLARE Lives : INTEGER
B DECLARE Score, Lives : INTEGER

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1DECLARE TotalToPay : REAL AThe colon between the identifier and the data type is missing. It should be DECLARE Counter : INTEGER
2DECLARE GameOver : BOOLEAN BCreates a variable called GameOver that can only store TRUE or FALSE
3A DECLARE line gives the variable name first, then a colon, then its data type CCreates a variable called TotalToPay that stores a real number, such as a price with decimals
4Use one DECLARE line for each variable, so two variables need two lines DDECLARE Counter : INTEGER
5DECLARE Counter INTEGER ETwo variables are declared on one line. Each variable needs its own DECLARE line
6DECLARE Counter, Total : INTEGER FDECLARE Score : INTEGER DECLARE GameOver : BOOLEAN

Definitions

DECLARE Counter : INTEGER

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
_______ Counter : INTEGER
2.
DECLARE TotalToPay : ____
3.
DECLARE GameOver : _______
4.
DECLARE Counter _ INTEGER
5.
DECLARE Counter : _______ Counter ← 0

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A DECLARE Counter INTEGER
B Counter ← 0
C OUTPUT Counter
Question 2
A DECLARE Score : INTEGER
B DECLARE Lives, Level : INTEGER
C Score ← 0
Question 3
A DECLARE Lives : INTEGER
B DECLARE GameOver : BOOLEAN
C DECLARE Score : INTEGER
D DECLARE Name : TEXT
Question 4
A DEFINE TotalToPay : REAL
B TotalToPay ← 12.5
C OUTPUT TotalToPay
Question 5
A DECLARE Counter : INTEGER
B DECLARE GameOver : BOOL
C Counter ← 0
D GameOver ← FALSE

Answer Key

DECLARE a variable (7a)
Section A: Quick Questions
Q1
A — DECLARE Counter : INTEGER
Q2
B — DECLARE TotalToPay : REAL
Q3
B — DECLARE GameOver : BOOLEAN
Q4
A — It creates a variable with a name and a data type
Q5
A — DECLARE Score : INTEGER DECLARE Lives : INTEGER
Section B: Match the Pairs
Q1
DECLARE TotalToPay : REAL → Creates a variable called TotalToPay that stores a real number, such as a price with decimals
Q2
DECLARE GameOver : BOOLEAN → Creates a variable called GameOver that can only store TRUE or FALSE
Q3
A DECLARE line gives the variable name first, then a colon, then its data type → DECLARE Counter : INTEGER
Q4
Use one DECLARE line for each variable, so two variables need two lines → DECLARE Score : INTEGER DECLARE GameOver : BOOLEAN
Q5
DECLARE Counter INTEGER → The colon between the identifier and the data type is missing. It should be DECLARE Counter : INTEGER
Q6
DECLARE Counter, Total : INTEGER → Two variables are declared on one line. Each variable needs its own DECLARE line
Section C: Definitions
Q1
DECLARE Counter : INTEGER — Creates a variable called Counter with the data type INTEGER. Form: DECLARE <identifier> : <data type>. Use one DECLARE line per variable.
Section D: Fill in the Blanks
Q1
DECLARE Counter : INTEGER
Q2
DECLARE TotalToPay : REAL
Q3
DECLARE GameOver : BOOLEAN
Q4
DECLARE Counter : INTEGER
Q5
DECLARE Counter : INTEGER Counter ← 0
Section E: Spot the Error
Q1
A — The colon between the identifier and the data type is missing. It should be DECLARE Counter : INTEGER.
Q2
B — Each DECLARE line creates only one variable. Lives and Level need separate DECLARE lines, so line 2 should be DECLARE Lives : INTEGER.
Q3
D — TEXT is not a Cambridge pseudocode data type. A word or sentence is stored as a STRING, so it should be DECLARE Name : STRING.
Q4
A — The keyword to create a variable is DECLARE, not DEFINE. It should be DECLARE TotalToPay : REAL.
Q5
B — BOOL is not a valid data type keyword. The full keyword must be used: DECLARE GameOver : BOOLEAN.