# User Input & Standard Arithmetic Operations

- **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

Interactive computing requires reading data dynamically from users and applying arithmetic transformations according to mathematical precedence rules.

---

## 1. Accepting Input (`INPUT`)

The `INPUT` statement reads data from an external input device (e.g. keyboard) and stores it in a declared variable:

```pseudocode
DECLARE StudentAge : INTEGER
OUTPUT "Please enter your age: "
INPUT StudentAge
```

---

## 2. Standard Arithmetic Operators

Cambridge pseudocode supports the five fundamental mathematical operators:

  
| Operator | Operation | Exam Example | Result |
| --- | --- | --- | --- |
| `+` | Addition | `12 + 8` | `20` |
| `-` | Subtraction | `25 - 9` | `16` |
| `*` | Multiplication | `6 * 7` | `42` |
| `/` | Real Division | `15 / 2` | `7.5` |
| `^` | Exponentiation (Power) | `2 ^ 3` | `8` |

---

## 3. Operator Precedence (BODMAS / PEMDAS)

When an expression contains multiple operators, operations are executed in a strict hierarchy:

1. **Brackets `(...)`**: Expressions inside parentheses evaluate first.
2. **Exponents `^`**: Evaluated next.
3. **Multiplication `*` and Division `/`**: Evaluated left to right.
4. **Addition `+` and Subtraction `-`**: Evaluated left to right.

```pseudocode
// Without parentheses (Multiplication first):
Result <- 10 + 5 * 2       // 10 + 10 = 20

// With parentheses:
Result <- (10 + 5) * 2     // 15 * 2 = 30
```

---

## 4. Cambridge Relational Operators

Relational operators compare two values and evaluate to a `BOOLEAN` result (`TRUE` or `FALSE`):

  
| Operator | Meaning | True Condition Example | False Condition Example |
| --- | --- | --- | --- |
| `=` | Equal to | `5 = 5` | `5 = 6` |
| `<>` | **Not equal to** | `5 <> 6` | `5 <> 5` |
| `<` | Less than | `3 < 7` | `7 < 3` |
| `<=` | Less than or equal to | `5 <= 5` | `6 <= 5` |
| `>` | Greater than | `9 > 4` | `4 > 9` |
| `>=` | Greater than or equal to | `8 >= 8` | `7 >= 8` |

---

## Interactive Exercises & Autotest Specifications

### Exercise 1: Exam-Style Check: Operator Precedence and Relational Symbols (Multiple choice, 25 XP)

**Instructions:**
Which symbol represents the relational operator "NOT EQUAL TO" in official Cambridge pseudocode?

**Options:**
- **A**: !=
- **B**: /=
- **C**: NE
- **D**: &lt;&gt;


**Autotest Expectations:**
- **Not equal operator identified**: `selection_match` -> Expected: `opt_angle`

### Exercise 2: Exam-Style Question: Evaluate Expression Precedence (Fill in blank, 35 XP)

**Instructions:**
Evaluate the final numerical values of `ResultA` and `ResultB`:

```pseudocode
ResultA <- 10 + 5 * 2
ResultB <- (10 + 5) * 2
```

Enter the values computed for `ResultA` [blank_1] and `ResultB` [blank_2].


**Starter Code:**
```text
{"template":"ResultA = [blank_1]\nResultB = [blank_2]","word_bank":["20","30","14","24","40","10"],"prompt":"Exam-Style Question: Evaluate Expression Precedence","blanks":[{"id":"blank_1"},{"id":"blank_2"}]}
```

**Autotest Expectations:**
- **ResultA is 20**: `text_exact` -> Expected: `20`
- **ResultB is 30**: `text_exact` -> Expected: `30`

### Exercise 3: Independent Practice: Rectangle measurements (Pseudocode, 30 XP)

**Instructions:**
Read positive integer length then width. Output area followed by perimeter. Choose the correct formula for each; do not confuse the two measurements.

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:**
- **Unequal sides**: `test_case` -> Expected: `{&quot;inputs&quot;:[8,3],&quot;output&quot;:&quot;24\n22&quot;}`
- **Unit square**: `test_case` -> Expected: `{&quot;inputs&quot;:[1,1],&quot;output&quot;:&quot;1\n4&quot;}`
- **Different rectangle**: `test_case` -> Expected: `{&quot;inputs&quot;:[12,5],&quot;output&quot;:&quot;60\n34&quot;}`

