INTEGER data type

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

INTEGER data type

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which value can be stored in an INTEGER variable?
A -3
B 3.5
2. Which declaration creates a variable to store the number of lives a player has?
A DECLARE Lives : INTEGER
B DECLARE Lives : STRING
3. True or false: an INTEGER can be negative.
A False, it must be 0 or more
B True, for example -3
4. Which is a valid INTEGER literal?
A 42.0
B 42
5. Which value is best stored as an INTEGER?
A The number of students in a class
B The average height of the students in metres

Match the Pairs

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

Left columnRight column
1DECLARE Lives : INTEGER ACreates a variable called Lives that can store a whole number, such as the number of lives left in a game
2Score ← -3 BStores a negative whole number in the variable Score, which is a valid INTEGER value
3An INTEGER variable holds a whole number with no fractional part, such as a count of items CCounter ← 5
4A valid INTEGER value is written in normal denary digits and can be positive or negative D2.5 has a fractional part, so it cannot be stored in an INTEGER variable. Use a whole number such as 2, or declare Lives as REAL.
5DECLARE Lives : INTEGER Lives ← 2.5 EDECLARE Counter : INTEGER
6DECLARE Counter : INTEGER Counter ← "5" F"5" is a STRING because it is in quotes, so it does not match INTEGER. Write the whole number 5 without quotes.

Definitions

INTEGER

Fill in the Blanks

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

1.
DECLARE Lives : _______
2.
DECLARE Change : _______ Change ← -3
3.
_______ Counter : INTEGER Counter ← 0
4.
DECLARE Lives : INTEGER _____ ← 3
5.
DECLARE Counter : INTEGER Counter ← 0 Counter ← Counter _ 1

Spot the Error

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

Question 1
A DECLARE Lives : INTEGER
B Lives ← 3
C Lives ← Lives - 0.5
D OUTPUT Lives
Question 2
A DECLARE Score : INTEGER
B Score ← 0
C Score ← Score + 10
D Score ← Score + 2.5
E OUTPUT Score
Question 3
A DECLARE Temp : INTEGER
B Temp ← "-3"
C OUTPUT Temp
Question 4
A DECLARE Count : INT
B Count ← 7
C OUTPUT Count
Question 5
A DECLARE Players : INTEGER
B Players ← 4.0
C OUTPUT Players

Answer Key

INTEGER data type
Section A: Quick Questions
Q1
A — -3
Q2
A — DECLARE Lives : INTEGER
Q3
B — True, for example -3
Q4
B — 42
Q5
A — The number of students in a class
Section B: Match the Pairs
Q1
DECLARE Lives : INTEGER → Creates a variable called Lives that can store a whole number, such as the number of lives left in a game
Q2
Score ← -3 → Stores a negative whole number in the variable Score, which is a valid INTEGER value
Q3
An INTEGER variable holds a whole number with no fractional part, such as a count of items → DECLARE Counter : INTEGER
Q4
A valid INTEGER value is written in normal denary digits and can be positive or negative → Counter ← 5
Q5
DECLARE Lives : INTEGER Lives ← 2.5 → 2.5 has a fractional part, so it cannot be stored in an INTEGER variable. Use a whole number such as 2, or declare Lives as REAL.
Q6
DECLARE Counter : INTEGER Counter ← "5" → "5" is a STRING because it is in quotes, so it does not match INTEGER. Write the whole number 5 without quotes.
Section C: Definitions
Q1
INTEGER — The data type for a whole number with no fractional part, written in denary digits, such as 5 or -3. Used for counts like lives: DECLARE Lives : INTEGER
Section D: Fill in the Blanks
Q1
DECLARE Lives : INTEGER
Q2
DECLARE Change : INTEGER Change ← -3
Q3
DECLARE Counter : INTEGER Counter ← 0
Q4
DECLARE Lives : INTEGER Lives ← 3
Q5
DECLARE Counter : INTEGER Counter ← 0 Counter ← Counter + 1
Section E: Spot the Error
Q1
C — Lives is an INTEGER, so it can only hold whole numbers. Subtracting 0.5 gives a value with a fractional part. It should subtract a whole number such as 1.
Q2
D — An INTEGER variable cannot store a number with a fractional part. 2.5 is a REAL value. It should add a whole number such as 5.
Q3
B — The quote marks make "-3" a STRING, not an INTEGER. A negative integer is written with a minus sign and digits only, with no quotes: Temp ← -3.
Q4
A — The Cambridge pseudocode data type for whole numbers is spelled INTEGER, not INT. It should be DECLARE Count : INTEGER.
Q5
B — 4.0 is written with a decimal point, so it is a REAL literal, not an INTEGER literal. A whole number is written with digits only: Players ← 4.