Declaring a variable with DECLARE (8.1b)

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

Declaring a variable with DECLARE (8.1b)

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 Count?
A DECLARE Count : STRING
B DECLARE Count : INTEGER
2. Which line correctly declares a variable to store a price such as 4.50?
A DECLARE Price : REAL
B DECLARE Price : INTEGER
3. True or false: DECLARE gives a variable its name and data type before the variable is used.
A True
B False
4. Which identifier is written correctly in Cambridge pseudocode?
A DECLARE Total Score : INTEGER
B DECLARE TotalScore : INTEGER
5. Which declaration is the correct one for a variable that stores a person's name?
A DECLARE Name : STRING
B DECLARE Name : BOOLEAN

Match the Pairs

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

Left columnRight column
1DECLARE Count : INTEGER AThe identifier contains a space. Identifiers must be one word with no spaces, e.g. TotalPrice.
2DECLARE Found : BOOLEAN BDECLARE Name : STRING
3Declare a variable to store a price with a decimal point, such as 4.99 CCreates a variable called Count that can only store whole numbers
4Declare a variable to store text such as a person's name DThe colon is missing between the identifier and the data type. It should be DECLARE Count : INTEGER.
5DECLARE Total Price : REAL ECreates a variable called Found that can only store TRUE or FALSE
6DECLARE Count INTEGER FDECLARE Price : REAL

Definitions

DECLARE Count : INTEGER

Fill in the Blanks

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

1.
_______ Count : INTEGER
2.
DECLARE Price : ____
3.
DECLARE Name : ______
4.
DECLARE Found : _______
5.
DECLARE _____ : INTEGER Total <- 0

Spot the Error

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

Question 1
A DECLARE Total : INTEGER
B DECLARE Price REAL
C Price <- 4.5
D Total <- 3
E OUTPUT Total * Price
Question 2
A DECLARE Name : STRING
B DECLARE Age : INTEGER
C Name <- "Sam"
D Age <- "fifteen"
Question 3
A DECLARE Count : INTEGER
B DECLARE Found : BOOLEAN
C Count <- 0
D Found <- 0
Question 4
A DECLARE Count : INTEGER
B DECLARE Price : REAL
C DECLARE Total Cost : REAL
D TotalCost <- Count * Price
Question 5
A DECLARE Total : INTEGER
B DECLARE Count : INTEGER
C DECLARE Average : INTEGER
D Average <- Total / Count

Answer Key

Declaring a variable with DECLARE (8.1b)
Section A: Quick Questions
Q1
B — DECLARE Count : INTEGER
Q2
A — DECLARE Price : REAL
Q3
A — True
Q4
B — DECLARE TotalScore : INTEGER
Q5
A — DECLARE Name : STRING
Section B: Match the Pairs
Q1
DECLARE Count : INTEGER → Creates a variable called Count that can only store whole numbers
Q2
DECLARE Found : BOOLEAN → Creates a variable called Found that can only store TRUE or FALSE
Q3
Declare a variable to store a price with a decimal point, such as 4.99 → DECLARE Price : REAL
Q4
Declare a variable to store text such as a person's name → DECLARE Name : STRING
Q5
DECLARE Total Price : REAL → The identifier contains a space. Identifiers must be one word with no spaces, e.g. TotalPrice.
Q6
DECLARE Count INTEGER → The colon is missing between the identifier and the data type. It should be DECLARE Count : INTEGER.
Section C: Definitions
Q1
DECLARE Count : INTEGER — Names a variable (Count) and gives its data type (INTEGER) before use. Other types: REAL, STRING, BOOLEAN. Identifiers are capitalised with no spaces.
Section D: Fill in the Blanks
Q1
DECLARE Count : INTEGER
Q2
DECLARE Price : REAL
Q3
DECLARE Name : STRING
Q4
DECLARE Found : BOOLEAN
Q5
DECLARE Total : INTEGER Total <- 0
Section E: Spot the Error
Q1
B — The colon between the identifier and the data type is missing. It should be DECLARE Price : REAL.
Q2
D — Age was declared as INTEGER, so it cannot store text. It should be Age <- 15.
Q3
D — Found was declared as BOOLEAN, so it can only hold TRUE or FALSE, not a number. It should be Found <- FALSE.
Q4
C — An identifier cannot contain a space. It should be DECLARE TotalCost : REAL.
Q5
C — An average can have decimal places, so Average should be declared as REAL, not INTEGER. It should be DECLARE Average : REAL.