DECLARE a variable (7c)

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

DECLARE a variable (7c)

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which line correctly declares a variable to count how many lives a player has left?
A DECLARE Lives INTEGER
B DECLARE Lives : INTEGER
2. Which line declares a variable to store a price that can include pence, such as 12.50?
A DECLARE TotalToPay : INTEGER
B DECLARE TotalToPay : REAL
3. Which line correctly declares a variable that holds TRUE or FALSE to show whether a game has ended?
A DECLARE GameOver : BOOLEAN
B DECLARE GameOver : STRING
4. When should DECLARE Counter : INTEGER appear in an algorithm?
A Before Counter is used
B After Counter has been used
5. Which line follows the standard layout for spacing around the colon?
A DECLARE Counter : INTEGER
B 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 Counter : INTEGER AThe variable is used before it is declared. The DECLARE line must come first, then the assignment.
2DECLARE GameOver : BOOLEAN BThe colon is missing. The correct format is DECLARE TotalToPay : REAL, with a space on each side of the colon.
3Declare a variable to store a price that has decimal places CDECLARE Counter : INTEGER Counter ← 0
4A variable must be declared before it is used, so DECLARE comes first DCreates a variable called GameOver that can only hold TRUE or FALSE
5Counter ← 0 DECLARE Counter : INTEGER ECreates a variable called Counter that can only store whole numbers
6DECLARE TotalToPay REAL FDECLARE TotalToPay : REAL

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 : INTEGER _______ ← 0

Spot the Error

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

Question 1
A DECLARE Counter : INTEGER
B DECLARE TotalToPay : REAL
C DECLARE GameOver BOOLEAN
Question 2
A declare Counter : INTEGER
B Counter ← 0
C OUTPUT Counter
Question 3
A DECLARE Score : INTEGER
B DECLARE Price : REAL
C DECLARE Name : STRING
D DECLARE Done : BOOL
Question 4
A DECLARE Total : INTEGER
B DECLARE Count:INTEGER
C Total ← 0
D Count ← 0
Question 5
A DECLARE Price : REAL
B DECLARE Qty : INTEGER
C Price ← 4.5
D Qty ← 2.5

Answer Key

DECLARE a variable (7c)
Section A: Quick Questions
Q1
B — DECLARE Lives : INTEGER
Q2
B — DECLARE TotalToPay : REAL
Q3
A — DECLARE GameOver : BOOLEAN
Q4
A — Before Counter is used
Q5
A — DECLARE Counter : INTEGER
Section B: Match the Pairs
Q1
DECLARE Counter : INTEGER → Creates a variable called Counter that can only store whole numbers
Q2
DECLARE GameOver : BOOLEAN → Creates a variable called GameOver that can only hold TRUE or FALSE
Q3
Declare a variable to store a price that has decimal places → DECLARE TotalToPay : REAL
Q4
A variable must be declared before it is used, so DECLARE comes first → DECLARE Counter : INTEGER Counter ← 0
Q5
Counter ← 0 DECLARE Counter : INTEGER → The variable is used before it is declared. The DECLARE line must come first, then the assignment.
Q6
DECLARE TotalToPay REAL → The colon is missing. The correct format is DECLARE TotalToPay : REAL, with a space on each side of the colon.
Section C: Definitions
Q1
DECLARE Counter : INTEGER — Creates a variable named Counter and states its data type (INTEGER) before it is used. The format is DECLARE <identifier> : <data type>, with a space on each side of the colon.
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
C — The colon is missing. The format is DECLARE <identifier> : <data type>, so it should be DECLARE GameOver : BOOLEAN.
Q2
A — Pseudocode keywords must be written in upper case. It should be DECLARE Counter : INTEGER.
Q3
D — BOOL is not a pseudocode data type. The correct data type name is BOOLEAN, so the line should be DECLARE Done : BOOLEAN.
Q4
B — There must be a space on each side of the colon. It should be DECLARE Count : INTEGER.
Q5
D — Qty was declared as INTEGER, so it can only store whole numbers. 2.5 is a REAL value, so use a whole number such as Qty ← 2.