# Constants, Scope & Value Protection

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

---

## Theory & Conceptual Background

A variable stores a value that may change. A constant names a value that does not change while the program runs. Naming a fixed price or limit makes its purpose clear and avoids repeating unexplained numbers.

```pseudocode
CONSTANT TicketPrice = 7
DECLARE Tickets : INTEGER
INPUT Tickets
OUTPUT TicketPrice * Tickets
```

## Worked example

For three tickets, the expression is 7 × 3 = 21. The number of tickets is input and may differ next time; TicketPrice stays fixed in this program. Changing the price in one declaration is easier to maintain than finding many occurrences of 7.

Do not write INPUT TicketPrice: input belongs in a variable. Scope—where an identifier can be used—is taught with procedures and functions, after you have seen those constructs.

---

## Interactive Exercises & Autotest Specifications

### Exercise 1: Exam-Style Check: Constant Declaration Syntax & Mutability (Multiple choice, 25 XP)

**Instructions:**
Which statement correctly declares a named constant for maximum capacity with the value 500 in Cambridge pseudocode?

**Options:**
- **A**: CONSTANT MaxCapacity &lt;- 500
- **B**: CONSTANT MaxCapacity : INTEGER = 500
- **C**: CONSTANT MaxCapacity = 500
- **D**: DECLARE CONSTANT MaxCapacity = 500


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

### Exercise 2: Application: Check the reasoning (Fill in blank, 30 XP)

**Instructions:**
Work out each answer before submitting. Identifier whose value stays fixed during execution: Should changing user input be stored in a constant or variable? Does a named constant help explain an otherwise unexplained number: yes or no?


**Starter Code:**
```text
{"prompt":"Application: Check the reasoning","template":"1. Identifier whose value stays fixed during execution: [blank_1]\n2. Should changing user input be stored in a constant or variable? [blank_2]\n3. Does a named constant help explain an otherwise unexplained number: yes or no? [blank_3]","blanks":[{"id":"blank_1"},{"id":"blank_2"},{"id":"blank_3"}],"word_bank":["constant","variable","parameter","yes","no","global"]}
```


### Exercise 3: Independent Practice: A fixed ticket price (Pseudocode, 30 XP)

**Instructions:**
Each ticket costs 7 units. Read the integer number of tickets and output the total price. Represent the fixed price with a named constant.

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:**
- **Three tickets**: `test_case` -> Expected: `{&quot;inputs&quot;:[3],&quot;output&quot;:&quot;21&quot;}`
- **No tickets**: `test_case` -> Expected: `{&quot;inputs&quot;:[0],&quot;output&quot;:&quot;0&quot;}`
- **Ten tickets**: `test_case` -> Expected: `{&quot;inputs&quot;:[10],&quot;output&quot;:&quot;70&quot;}`

