REAL data type

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

REAL data type

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which value is a REAL literal in Cambridge pseudocode?
A 4.7
B 47
2. Which data type should you choose for TotalToPay, which holds 12.50 (money)?
A INTEGER
B REAL
3. Which literal is REAL?
A 5.0
B 5
4. Which is the correct way to write a REAL value of three tenths?
A .3
B 0.3
5. Which is the correct way to write a REAL value of four?
A 4.0
B 4.

Match the Pairs

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

Left columnRight column
1DECLARE TotalToPay : REAL AA REAL must have a digit after the decimal point, so 12. is invalid. It should be 12.0.
2Height ← 0.3 BCount ← 5 Length ← 5.0
35 is an INTEGER because it has no decimal point, but 5.0 is a REAL CTemperature ← -4.0
4A negative REAL still has a digit on each side of the point, even when its fractional part is zero DA REAL must have a digit before the decimal point, so .5 is invalid. It should be 0.5.
5Price ← .5 ECreates a variable that can store a number with a fractional part, such as a price
6TotalToPay ← 12. FAssigns a REAL literal with a digit on each side of the point

Definitions

REAL

Fill in the Blanks

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

1.
DECLARE Price : ____ Price ← 4.7
2.
_______ Height : REAL Height ← 1.5
3.
DECLARE Distance : REAL Distance ← ___ // five as a REAL value
4.
DECLARE __________ : REAL TotalToPay ← 12.5
5.
DECLARE Count : _______ Count ← 5

Spot the Error

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

Question 1
A DECLARE Price : REAL
B Price ← .7
C OUTPUT Price
Question 2
A DECLARE Height : INTEGER
B Height ← 1.75
C OUTPUT Height
Question 3
A DECLARE TotalToPay : REAL
B TotalToPay ← 0.0
C TotalToPay ← 9,99
D OUTPUT TotalToPay
Question 4
A DECLARE Temp : REAL
B Temp ← 21.5
C Temp ← -4.
D OUTPUT Temp
Question 5
A DECLARE Mass : REAL
B DECLARE Count : INTEGER
C Count ← 5.0
D OUTPUT Count

Answer Key

REAL data type
Section A: Quick Questions
Q1
A — 4.7
Q2
B — REAL
Q3
A — 5.0
Q4
B — 0.3
Q5
A — 4.0
Section B: Match the Pairs
Q1
DECLARE TotalToPay : REAL → Creates a variable that can store a number with a fractional part, such as a price
Q2
Height ← 0.3 → Assigns a REAL literal with a digit on each side of the point
Q3
5 is an INTEGER because it has no decimal point, but 5.0 is a REAL → Count ← 5 Length ← 5.0
Q4
A negative REAL still has a digit on each side of the point, even when its fractional part is zero → Temperature ← -4.0
Q5
Price ← .5 → A REAL must have a digit before the decimal point, so .5 is invalid. It should be 0.5.
Q6
TotalToPay ← 12. → A REAL must have a digit after the decimal point, so 12. is invalid. It should be 12.0.
Section C: Definitions
Q1
REAL — The data type for a number that can have a fractional part, written with a digit on each side of the point, such as 4.7 or 0.3. 5 is an INTEGER but 5.0 is REAL.
Section D: Fill in the Blanks
Q1
DECLARE Price : REAL Price ← 4.7
Q2
DECLARE Height : REAL Height ← 1.5
Q3
DECLARE Distance : REAL Distance ← 5.0 // five as a REAL value
Q4
DECLARE TotalToPay : REAL TotalToPay ← 12.5
Q5
DECLARE Count : INTEGER Count ← 5
Section E: Spot the Error
Q1
B — A REAL literal needs at least one digit on each side of the decimal point. .7 should be written 0.7.
Q2
A — Height stores 1.75, which has a fractional part. An INTEGER cannot hold it, so the variable must be declared as REAL.
Q3
C — A REAL literal uses a decimal point, not a comma. It should be 9.99.
Q4
C — A REAL literal needs a digit after the decimal point as well as before it. -4. should be -4.0.
Q5
C — 5.0 is a REAL value, but Count is an INTEGER. The whole number 5 must be assigned instead.