Declaring a variable with DECLARE (8.1a)

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

Declaring a variable with DECLARE (8.1a)

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 Counter = INTEGER
2. Which line declares a variable to store a price that can have pence, such as 12.75?
A DECLARE TotalToPay : INTEGER
B DECLARE TotalToPay : REAL
3. Which line declares a variable that stores TRUE or FALSE?
A DECLARE GameOver : STRING
B DECLARE GameOver : BOOLEAN
4. Which is the correct layout of a DECLARE statement in Cambridge pseudocode?
A DECLARE Counter : INTEGER
B DECLARE Counter: INTEGER
5. Which program declares the variable at the correct time?
A DECLARE Counter : INTEGER Counter ← 0
B Counter ← 0 DECLARE Counter : 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 ACreates a variable called TotalToPay that can hold numbers with decimal places, such as a price
2DECLARE GameOver : BOOLEAN BCreates a variable called GameOver that can only hold TRUE or FALSE
3To create a variable that stores whole numbers, write DECLARE, then the name, a colon and the data type INTEGER CThe colon is missing between the identifier and the data type. It should be DECLARE Counter : INTEGER
4A variable must be declared before it is used, so DECLARE comes on the line before the first assignment DThe variable is used before it is declared. The DECLARE line must come before the assignment
5DECLARE Counter INTEGER EDECLARE Score : INTEGER Score ← 0
6Total ← 0 DECLARE Total : INTEGER FDECLARE Counter : INTEGER

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 _ BOOLEAN
4.
DECLARE Counter : _______ Counter ← 5
5.
DECLARE Lives : INTEGER _____ ← 3 OUTPUT Lives

Spot the Error

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

Question 1
A // Game setup
B DECLARE Counter : INTEGER
C Counter ← 0
D DECLARE GameOver : BOOL
Question 2
A DECLARE Counter : INTEGER
B Counter ← 0
C DECLARE TotalToPay REAL
D TotalToPay ← 9.99
Question 3
A DECLARE Score : INTEGER
B DECLARE Price: REAL
C Score ← 10
Question 4
A DECLARE Lives : INTEGER
B DECLARE BOOLEAN : GameOver
C Lives ← 3
D GameOver ← FALSE
Question 5
A DECLARE Age : INTEGER
B DECLARE Height : REAL
C DEFINE Name : STRING
D Age ← 15

Answer Key

Declaring a variable with DECLARE (8.1a)
Section A: Quick Questions
Q1
A — DECLARE Counter : INTEGER
Q2
B — DECLARE TotalToPay : REAL
Q3
B — DECLARE GameOver : BOOLEAN
Q4
A — DECLARE Counter : INTEGER
Q5
A — DECLARE Counter : INTEGER Counter ← 0
Section B: Match the Pairs
Q1
DECLARE TotalToPay : REAL → Creates a variable called TotalToPay that can hold numbers with decimal places, such as a price
Q2
DECLARE GameOver : BOOLEAN → Creates a variable called GameOver that can only hold TRUE or FALSE
Q3
To create a variable that stores whole numbers, write DECLARE, then the name, a colon and the data type INTEGER → DECLARE Counter : INTEGER
Q4
A variable must be declared before it is used, so DECLARE comes on the line before the first assignment → DECLARE Score : INTEGER Score ← 0
Q5
DECLARE Counter INTEGER → The colon is missing between the identifier and the data type. It should be DECLARE Counter : INTEGER
Q6
Total ← 0 DECLARE Total : INTEGER → The variable is used before it is declared. The DECLARE line must come before the assignment
Section C: Definitions
Q1
DECLARE Counter : INTEGER — Creates a variable called Counter that can only hold whole numbers. Use DECLARE name : TYPE, with a space either side of the colon, before you use the variable.
Section D: Fill in the Blanks
Q1
DECLARE Counter : INTEGER
Q2
DECLARE TotalToPay : REAL
Q3
DECLARE GameOver : BOOLEAN
Q4
DECLARE Counter : INTEGER Counter ← 5
Q5
DECLARE Lives : INTEGER Lives ← 3 OUTPUT Lives
Section E: Spot the Error
Q1
D — BOOL is not a Cambridge pseudocode data type. The type must be written in full as BOOLEAN: DECLARE GameOver : BOOLEAN.
Q2
C — The colon is missing between the identifier and the data type. It should be DECLARE TotalToPay : REAL.
Q3
B — There must be a space on both sides of the colon. The line should be DECLARE Price : REAL.
Q4
B — The identifier and the data type are the wrong way round. The name comes first, then the colon, then the type: DECLARE GameOver : BOOLEAN.
Q5
C — DEFINE is not a pseudocode keyword. A variable is created with the keyword DECLARE: DECLARE Name : STRING.