Learn
8.1.2 | INTEGER, REAL, CHAR, STRING AND BOOLEAN
01 | NOT ALL DATA MEANS THE SAME THING
A school booking program needs a number of tickets, a ticket price, a student’s name, a seating-zone letter and a paid-or-unpaid status. These are all data, but they are not all the same kind of information.
You calculate with a quantity and a price. You display a name as text. You use a payment status to choose what happens next. A data type describes the kind of value an item is intended to hold, helping determine which operations make sense.
Cambridge names five basic types for this section: INTEGER, REAL, CHAR, STRING and BOOLEAN. The important skill is not just recalling the names. It is choosing a type from the meaning of the data and its intended use.
We will build a small booking example as each type is introduced. All notation is Cambridge pseudocode; particular programming languages may use different names and syntax.
02 | INTEGER: WHOLE-NUMBER VALUES
An INTEGER holds a whole number, with no fractional part. Examples include zero, twelve and minus three. Whole number does not mean positive: negative values can also be integers.
DECLARE TicketQuantity : INTEGER TicketQuantity ← 3 DECLARE Temperature : INTEGER Temperature ← -2
A ticket quantity normally counts complete tickets, so INTEGER is suitable. In a scenario recording temperatures only as whole degrees, INTEGER can also suit a negative reading.
The type alone does not enforce every rule. An integer can be negative, even though a ticket quantity may be required to be non-negative. That restriction needs a validation rule.
Choose INTEGER for an item count, loop counter or whole-number score when the scenario specifies no fractional values. Do not use it for a measurement that needs values such as twenty-one point five.
03 | REAL: NUMBERS THAT CAN HAVE A FRACTIONAL PART
A REAL is a number capable of containing a fractional part. Prices, calculated means and measurements can require this type.
DECLARE TicketPrice : REAL DECLARE TotalCost : REAL TicketPrice ← 4.50 TotalCost ← 3 * TicketPrice
TotalCost becomes thirteen point five. REAL is suitable because a price need not be a whole number. A REAL can also hold a whole-valued quantity such as four point zero; it does not have to have a non-zero fractional part.
Cambridge REAL literals are written with at least one digit on each side of the decimal point, such as 0.5, 4.0 and -2.5. Use 0.5 rather than .5 in these pseudocode examples.
A mean may require REAL even if every input is INTEGER. Scores one and two have mean one point five. Type choice must account for the result, not only the input values.
04 | CHAR: EXACTLY ONE CHARACTER
A CHAR holds a single character. That character can be a letter, digit, punctuation symbol or space. It is not limited to alphabetical letters.
DECLARE SeatZone : CHAR SeatZone ← 'B' DECLARE MenuChoice : CHAR MenuChoice ← '2'
The seat zone uses one character, B. The menu choice is the character two, not automatically the numeric quantity two. It can be compared with another menu-choice character.
In Cambridge pseudocode, CHAR literals use single quotes: 'B', '2' or '@'. A space written between single quotes is one character. An empty pair of quotes is not a one-character value.
A two-letter code such as AB needs STRING rather than CHAR. Use CHAR only when the information is defined as one character.
05 | STRING: A SEQUENCE OF CHARACTERS
A STRING holds a sequence of zero or more characters. Names, messages and identifiers are common examples.
DECLARE StudentName : STRING DECLARE TicketCode : STRING StudentName ← "Maya" TicketCode ← "0072"
In Cambridge pseudocode, STRING literals use double quotes. A string can contain letters, spaces, digits and punctuation; it does not have to be a word.
The empty string, "", contains zero characters. It may be a useful starting value, but it would fail a requirement that a name must be supplied.
A string can also contain just one character, such as "B". That is still a STRING literal in this notation, whereas 'B' is a CHAR literal. Length alone is not the entire distinction: the declared type and literal notation also matter.
06 | NUMERIC-LOOKING DATA CAN STILL BE TEXT
A ticket code of 0072 identifies a ticket. You do not add ticket codes or calculate their mean. The leading zeros form part of the code and should be retained.
Representing it as an ordinary integer gives the numeric value seventy-two, rather than preserving the original four-character text. A STRING stores "0072" as an identifier.
| Data | Suitable type | Reason |
|---|---|---|
| Number of tickets: 72 | INTEGER | A whole-number quantity used in calculations |
| Ticket code: "0072" | STRING | Text identifier; leading zeros matter |
| Telephone number | STRING | Identifying/contact text, possibly with + or leading zeros |
| Measured distance: 72.5 | REAL | A quantity with a fractional part |
Quoted numeric text such as "12" is not automatically the numeric value twelve. Arithmetic needs appropriate numeric values. In an implementation, conversion may be required, but receiving text does not itself guarantee that conversion is valid.
Do not assume that an item called a number must be INTEGER. A phone number and a number of students have different roles.
07 | BOOLEAN: A TWO-STATE VALUE
A BOOLEAN holds one of the logical values TRUE or FALSE. It is useful for a yes-or-no state: whether a booking is paid, whether an item was found or whether a game is over.
DECLARE PaymentComplete : BOOLEAN PaymentComplete ← FALSE PaymentComplete ← TRUE
The initial value says payment is not complete. A later assignment records that it is. The variable’s name should make the meaning of TRUE clear.
Cambridge Boolean literals are TRUE and FALSE without quotation marks. "TRUE" is a string of four characters, not the Boolean value TRUE.
A Boolean is not a third-state item that also holds unknown. If the task needs an extra state such as pending, the data design needs to account for that separately. For this section, remember exactly two logical values.
08 | CONDITIONS PRODUCE BOOLEAN RESULTS
A comparison such as Score >= 10 produces a Boolean result. It is true or false depending on the current score.
DECLARE Score : INTEGER DECLARE TargetReached : BOOLEAN Score ← 12 TargetReached ← Score >= 10
Score is twelve, so the comparison is true and TargetReached receives TRUE. If Score had been seven, the comparison would have produced FALSE.
Assigning the result does not create a live link. If Score later changes to seven without recalculating TargetReached, TargetReached still holds TRUE. A new assignment is needed to update the stored result.
An IF statement can use a Boolean value to choose a branch. A value of FALSE is a valid logical result; it does not automatically mean the program has an error.
09 | THE FIVE TYPES AT A GLANCE
| Type | What it represents | Literal examples | Typical use |
|---|---|---|---|
| INTEGER | Whole number | 0, 12, -3 | Quantity or counter |
| REAL | Number capable of a fractional part | 0.5, 4.0, -2.5 | Price, measurement or mean |
| CHAR | One character | 'B', '2', '@' | Single-character option |
| STRING | Zero or more characters | "Maya", "0072", "" | Name, message or identifier |
| BOOLEAN | Logical value | TRUE, FALSE | Status or condition result |
A literal is a value written directly into an instruction. A variable identifier names an item that currently holds a value. The literal notation helps make the intended type clear.
The type distinction is independent of variable versus constant. A numeric price can be a fixed constant, while a numeric total can be a changing variable. Text can also be either fixed or changing, according to its role.
10 | READ A COMPLETE BOOKING EXAMPLE
This example prepares a booking record from illustrative values. It demonstrates declarations and assignment, not a full booking or payment system.
DECLARE TicketQuantity : INTEGER DECLARE TicketPrice : REAL DECLARE TotalCost : REAL DECLARE SeatZone : CHAR DECLARE StudentName : STRING DECLARE TicketCode : STRING DECLARE PaymentComplete : BOOLEAN TicketQuantity ← 3 TicketPrice ← 4.50 TotalCost ← TicketQuantity * TicketPrice SeatZone ← 'B' StudentName ← "Maya" TicketCode ← "0072" PaymentComplete ← FALSE OUTPUT "Student: ", StudentName OUTPUT "Ticket code: ", TicketCode OUTPUT "Zone: ", SeatZone OUTPUT "Total: ", TotalCost
TicketQuantity counts three tickets. TicketPrice and TotalCost allow fractional amounts. SeatZone is one character, StudentName and TicketCode are text sequences, and PaymentComplete records a two-state status.
TotalCost is thirteen point five. The ticket code remains 0072. PaymentComplete is FALSE, but this example does not yet branch on that state.
The exact formatting of prices and Boolean display is a separate output concern. Choosing a type establishes meaning and permitted values; it does not automatically apply currency formatting or validation.
11 | CHOOSE A TYPE AND JUSTIFY IT
A good justification connects the data requirement to the type. “It is a number” is often too vague.
Quantity: “TicketQuantity is INTEGER because tickets are counted in whole units.”
Mean: “AverageScore is REAL because division can produce a fractional result even when the original scores are whole numbers.”
Code: “TicketCode is STRING because it is an identifier and must preserve leading zeros, rather than being used as a numeric quantity.”
Status: “PaymentComplete is BOOLEAN because the required state has two outcomes, complete or not complete.”
The scenario decides. A measurement rounded to whole units might use INTEGER; a measurement requiring fractional precision needs REAL. State the relevant assumption when the wording is unclear.
12 | RECOGNISE MISMATCHED VALUES
A declared type should match the values assigned to it. Do not rely on unspecified automatic conversion.
| Intended declaration and value | Issue | Suitable change |
|---|---|---|
| DECLARE Quantity : INTEGER; Quantity ← 3.5 | A fractional quantity does not fit INTEGER | Use REAL only if fractional quantities are actually permitted |
| DECLARE Zone : CHAR; Zone ← 'AB' | Two characters do not form a CHAR literal | Use STRING and "AB" for a two-character code |
| DECLARE Name : STRING; Name ← "Maya" | No mismatch | Keep STRING |
| DECLARE Paid : BOOLEAN; Paid ← "TRUE" | Quoted text is not a Boolean literal | Assign TRUE if that is the intended logical value |
Changing INTEGER to REAL simply to silence a mismatch can be wrong if the task only permits whole tickets. Check the requirement, then reject invalid input or choose the correct representation.
A type is not the same as validation. An INTEGER mark can still be outside a permitted range; a STRING name can still be empty when presence is required.
13 | TRACE VALUES AND TYPES TOGETHER
Follow this short fragment with suitable declarations: Quantity is INTEGER, Price and Total are REAL, Code is STRING and Ready is BOOLEAN.
Quantity ← 2 Price ← 3.50 Total ← Quantity * Price Code ← "002" Ready ← Total >= 7.0 Quantity ← 3
| Item | Final value | Why |
|---|---|---|
| Quantity | 3 | Last assignment changes it |
| Price | 3.50 | No later update |
| Total | 7.0 | Calculated from the earlier quantity of two |
| Code | "002" | Text retains its leading zeros |
| Ready | TRUE | Stored result of seven being at least seven |
Quantity and Code both relate to the digit two earlier in the run, but their meanings differ. One is a quantity; the other is an identifier.
To refresh Total after Quantity changes, explicitly repeat Total ← Quantity * Price. To refresh Ready after Total changes, repeat its comparison assignment too.
14 | AVOID THE COMMON MIX-UPS
INTEGER means positive: it also includes zero and negative whole numbers.
REAL means a non-zero fractional part: it can hold a whole-valued number too.
CHAR means a letter: a single digit or punctuation symbol can also be a character.
STRING must contain several characters: it can contain one or zero.
Digits always mean numeric data: identifiers can be numeric-looking strings.
"FALSE" is Boolean: the quoted form is text; FALSE without quotes is the Boolean literal.
Correct type means valid input: range, presence and other rules still need separate checking.
When unsure, ask what the information means, what values it may contain and what operations the algorithm needs to perform.
15 | TRANSFER YOUR UNDERSTANDING
Try choosing types for a weather logger: a whole-number reading count, a fractional temperature, a one-character sensor label, a station identifier and an alarm-active flag. Explain each choice before checking a model answer.
The same five types recur across scenarios. Learning the meaning lets you adapt your choices rather than memorising that every name, code or measurement always uses one particular type.
The next lesson uses these named values with INPUT, OUTPUT and user prompts. Keep the distinction between the value’s type, how it is received and how it is displayed.