# Variables, Data Types & OUTPUT in Cambridge Pseudocode

- **Track:** Cambridge IGCSE™ Computer Science (0478 / 0984) (CAMBRIDGE IGCSE 0478)
- **Module:** Section 8: Programming Concepts & File Handling
- **Estimated Duration:** 15 minutes
- **Access:** Open Theory (All-Access for Interactive IDE &amp; Autotests)

---

## Theory & Conceptual Background

Programming begins with representing and manipulating data in computer memory. In Cambridge IGCSE Computer Science, algorithms are formalized using standardized pseudocode conventions.

---

## 1. What is a Variable?

A **Variable** is a named location in computer memory whose value can change during program execution:

- Each variable has an **Identifier** (name), a **Data Type**, and a **Current Value**.
- In Cambridge pseudocode, all variables **must be declared explicitly** before they can be assigned values or referenced.

### Declaration Syntax:

```pseudocode
DECLARE <Identifier> : <DataType>
```

---

## 2. Standard Cambridge Data Types

  
| Data Type | Definition | Memory Representation & Range | Example Cambridge Literals |
| --- | --- | --- | --- |
| `INTEGER` | Whole numbers (positive, negative, zero) without decimals. | Typically stored in 2 to 4 bytes using two's complement. | `0`, `42`, `-15`, `1000` |
| `REAL` | Numbers with fractional or decimal components. | Stored using floating-point representation (mantissa & exponent). | `3.14159`, `19.99`, `-0.75` |
| `CHAR` | Exactly one alphanumeric character, symbol, or space. | One character; encoded byte width depends on the encoding. Enclosed in single quotes. | `'A'`, `'7'`, `'#'`, `' '` |
| `STRING` | An ordered sequence of zero or more characters. | Enclosed in double quotes. | `"Cambridge IGCSE"`, `""` |
| `BOOLEAN` | Logical truth states; takes only one of two values. | Evaluates exclusively to `TRUE` or `FALSE`. | `TRUE`, `FALSE` |

---

## 3. The Assignment Operator (`<-`)

In Cambridge pseudocode, the assignment operator is the arrow **`<-`**:

```pseudocode
TotalMark <- 85
StudentName <- "Sarah"
IsEnrolled <- TRUE
```

*Exam Warning*: Using `=` for assignment (e.g. `TotalMark = 85`) uses the wrong operator. The `=` symbol is reserved solely for relational equality comparisons in conditions.

---

## 4. Producing Output (`OUTPUT`)

The `OUTPUT` statement transmits text, variables, or expressions to the user interface:

```pseudocode
OUTPUT "Candidate Name: ", StudentName
OUTPUT "Final Score: ", TotalMark, " / 100"
```

Multiple items are separated by commas. String literals must always be enclosed in double quotes.

---

## Interactive Exercises & Autotest Specifications

### Exercise 1: Exam-Style Check: Identify Correct Variable Declarations (Multiple choice, 25 XP)

**Instructions:**
Which statement is the syntactically correct declaration for a variable named `TotalCost` that will store monetary decimal amounts in Cambridge pseudocode?

**Options:**
- **A**: DECLARE TotalCost : FLOAT
- **B**: DECLARE TotalCost : REAL
- **C**: DIM TotalCost AS REAL
- **D**: TotalCost : REAL


**Autotest Expectations:**
- **Correct declaration chosen**: `selection_match` -> Expected: `opt_real`

### Exercise 2: Exam-Style Question: Trace Variable Assignments and Output (Trace table, 35 XP)

**Instructions:**
### Task

Trace the execution of this algorithm:

```pseudocode
Score1 <- 15
Score2 <- 25
Total <- Score1 + Score2
Score1 <- Score1 * 2
OUTPUT "Score: ", Score1, " Total: ", Total
```

Complete the trace table rows.


**Starter Code:**
```text
{"columns": ["Score1", "Score2", "Total", "OUTPUT"], "rows": [["", "", "", ""], ["", "", "", ""], ["", "", "", ""], ["", "", "", ""], ["", "", "", ""]]}
```

**Autotest Expectations:**
- **Variable assignment and output trace matches expected values**: `table_match` -> Expected: ``

### Exercise 3: Independent Practice: A student record (Pseudocode, 30 XP)

**Instructions:**
Read a student name followed by an integer score. Store each using an appropriate type. Output the name, then the score, on separate lines.

Write a complete program. Read inputs in the stated order. Output only the requested results, one per line, without input prompts. Test with your own values before submitting.


**Starter Code:**
```text
// Plan your solution, then write your program.

```

**Autotest Expectations:**
- **First record**: `test_case` -> Expected: `{&quot;inputs&quot;:[&quot;Leila&quot;,82],&quot;output&quot;:&quot;Leila\n82&quot;}`
- **Zero score**: `test_case` -> Expected: `{&quot;inputs&quot;:[&quot;Ari&quot;,0],&quot;output&quot;:&quot;Ari\n0&quot;}`

