Choosing between INTEGER and REAL

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

Choosing between INTEGER and REAL

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which data type should you use to store the number of students in a class?
A INTEGER
B REAL
2. Which data type should you use to store the price of a sandwich, such as 3.75?
A REAL
B INTEGER
3. Which data type suits a variable called AverageMark that holds the mean of several test marks?
A INTEGER
B REAL
4. Which declaration is the better choice for the number of books in a bag? A: DECLARE Books : INTEGER B: DECLARE Books : REAL
A B: DECLARE Books : REAL
B A: DECLARE Books : INTEGER
5. True or false: a value that is whole today, such as a price of 5, should always be stored as INTEGER.
A False
B True

Match the Pairs

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

Left columnRight column
1DECLARE NumStudents : INTEGER ADECLARE NumSeats : INTEGER
2DECLARE AverageMark : REAL BDECLARE Price : REAL
3A price can include pence or cents, so it needs a data type that allows decimals CAn average mark can have a decimal part, so it should be declared as REAL. INTEGER cannot store 72.5.
4A value that is always a whole number, such as the number of seats in a room, uses INTEGER DStores a count of students, which is always a whole number
5DECLARE AverageMark : INTEGER AverageMark ← 72.5 EStores an average mark, which might have a decimal part
6DECLARE NumStudents : REAL FA count of students is always a whole number, so INTEGER is the better choice. REAL is not needed here.

Definitions

INTEGER or REAL

Fill in the Blanks

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

1.
DECLARE NumStudents : _______
2.
DECLARE Price : ____
3.
DECLARE AverageMark : ____ AverageMark ← 72.5
4.
DECLARE NumTickets : _______ NumTickets ← 4
5.
// Pocket money may include cents later DECLARE PocketMoney : ____

Spot the Error

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

Question 1
A DECLARE price : REAL
B DECLARE items : INTEGER
C price ← 4.50
D items ← 12.5
Question 2
A DECLARE avgMark : REAL
B DECLARE numStudents : REAL
C numStudents ← 30
D avgMark ← 67.5
Question 3
A DECLARE count : INTEGER
B count ← 12
C DECLARE price : INTEGER
D price ← 9.99
Question 4
A DECLARE total : INTEGER
B DECLARE average : INTEGER
C total ← 250
D average ← total / 4
Question 5
A DECLARE temp : INTEGER
B temp ← 21.5
C OUTPUT temp

Answer Key

Choosing between INTEGER and REAL
Section A: Quick Questions
Q1
A — INTEGER
Q2
A — REAL
Q3
B — REAL
Q4
B — A: DECLARE Books : INTEGER
Q5
A — False
Section B: Match the Pairs
Q1
DECLARE NumStudents : INTEGER → Stores a count of students, which is always a whole number
Q2
DECLARE AverageMark : REAL → Stores an average mark, which might have a decimal part
Q3
A price can include pence or cents, so it needs a data type that allows decimals → DECLARE Price : REAL
Q4
A value that is always a whole number, such as the number of seats in a room, uses INTEGER → DECLARE NumSeats : INTEGER
Q5
DECLARE AverageMark : INTEGER AverageMark ← 72.5 → An average mark can have a decimal part, so it should be declared as REAL. INTEGER cannot store 72.5.
Q6
DECLARE NumStudents : REAL → A count of students is always a whole number, so INTEGER is the better choice. REAL is not needed here.
Section C: Definitions
Q1
INTEGER or REAL — Use INTEGER for values that are always whole numbers, like a count of students. Use REAL if the value could have a decimal part, like a price or an average mark.
Section D: Fill in the Blanks
Q1
DECLARE NumStudents : INTEGER
Q2
DECLARE Price : REAL
Q3
DECLARE AverageMark : REAL AverageMark ← 72.5
Q4
DECLARE NumTickets : INTEGER NumTickets ← 4
Q5
// Pocket money may include cents later DECLARE PocketMoney : REAL
Section E: Spot the Error
Q1
D — items is an INTEGER, so it can only hold whole numbers. 12.5 has a decimal part. The line should be items ← 12.
Q2
B — A number of students is always a whole number, so it should be declared as INTEGER, not REAL.
Q3
C — A price such as 9.99 has a decimal part, so price must be declared as REAL. An INTEGER cannot store it.
Q4
B — An average can have a fractional part. 250 / 4 is 62.5, so average should be declared as REAL.
Q5
A — The temperature 21.5 has a decimal part, so temp must be REAL. INTEGER only holds whole numbers.