Welcome to Arithmetic Operations!

Hello! Today, we are going to look at how computers handle math. You might think, "I already know how to do math!" and you’re right—but computers have a few special ways of breaking down numbers that make programming much more powerful. Whether you are building a simple calculator or a massive video game, these arithmetic operations are the building blocks you will use every single day. Don't worry if some of the terms like "modulo" sound strange at first; by the end of these notes, you'll be using them like a pro!

1. The Basics: Addition, Subtraction, and Multiplication

Most of the math in programming looks exactly like the math you do in school. However, we use specific symbols called operators to tell the computer what to do.

Addition (+) and Subtraction (-)

These work exactly as you expect. You can add or subtract whole numbers (integers) or numbers with decimals (real numbers).
Example: \( 5 + 3 = 8 \) or \( 10.5 - 2.5 = 8.0 \)

Multiplication (*)

In programming, we don't use an 'x' for multiplication because the computer might think it's a letter. Instead, we use the asterisk symbol (\( * \)).
Example: \( 4 * 3 = 12 \)

Quick Review:
+ is for Addition
- is for Subtraction
* is for Multiplication

2. The Three Ways to Divide

This is where computer science gets interesting! In the AQA syllabus, you need to know three different ways to divide numbers. Depending on what you want the answer to look like, you'll choose a different operator.

Real Division (/)

This is "normal" division. It gives you the full answer, including the decimal points. We use the forward slash symbol.
Example: \( 11 / 2 = 5.5 \)

Integer Division (DIV)

Sometimes, you only want to know how many whole times a number goes into another. Integer division (often written as DIV) ignores the remainder and the decimal part completely. It effectively "rounds down" to the nearest whole number.
Example: \( 11 \text{ DIV } 2 = 5 \)

Remainder or Modulo (MOD)

What if you only care about what is left over? The modulo operator (often written as MOD or represented by a \( % \) symbol in some languages) gives you just the remainder.
Example: \( 11 \text{ MOD } 2 = 1 \) (Because 2 goes into 11 five times, with 1 left over).

Key Takeaway: Real division gives the "exact" answer, DIV gives the whole number, and MOD gives the leftovers.

3. The Pizza Analogy (Understanding DIV and MOD)

If you find DIV and MOD confusing, just think about a pizza party!

Imagine you have 11 slices of pizza and 2 very hungry friends. You want to be fair and give everyone the same amount of whole slices.

1. DIV: How many whole slices does each person get? They each get 5 whole slices. \( 11 \text{ DIV } 2 = 5 \).
2. MOD: After giving everyone their 5 slices, how many slices are left in the box? There is 1 slice left. \( 11 \text{ MOD } 2 = 1 \).
3. Real Division (/): If you were a perfectionist and cut the last slice in half so everyone got exactly the same total amount? Each person gets 5.5 slices. \( 11 / 2 = 5.5 \).

4. Step-by-Step: How to Calculate DIV and MOD

When you see a problem like \( 17 \text{ DIV } 3 \) and \( 17 \text{ MOD } 3 \), follow these steps:

1. Step One: Do the division in your head or on paper. How many times does 3 go into 17 without going over? (3, 6, 9, 12, 15... 18 is too high!)
2. Step Two: The answer is 5. So, \( 17 \text{ DIV } 3 = 5 \).
3. Step Three: Multiply your answer back: \( 5 * 3 = 15 \).
4. Step Four: Find the difference between your target (17) and that number (15). \( 17 - 15 = 2 \).
5. Step Five: That difference is your remainder. So, \( 17 \text{ MOD } 3 = 2 \).

Did you know?
Programmers use MOD all the time to check if a number is even or odd. If \( \text{Number MOD } 2 \) equals 0, the number is even. If it equals 1, the number is odd!

5. Common Mistakes to Avoid

1. Confusing / and DIV:
Remember, / is for decimals (Real Division), and DIV is for whole numbers only. If an exam question asks for a "real" result, use the slash!

2. Forgetting the Remainder:
In DIV, we don't round up. Even if the answer is 5.999, \( \text{Integer Division} \) will still result in 5 because it only counts completed whole groups.

Summary Checklist

Before you move on, make sure you can answer these:
- Can I identify the symbols for addition, subtraction, and multiplication? (+, -, *)
- Do I know that Real Division (/) includes decimals?
- Can I explain that Integer Division (DIV) gives only the whole number part?
- Can I explain that Remainder/Modulo (MOD) gives only the leftover part?
- Can I calculate DIV and MOD for simple numbers?

Don't worry if this seems tricky at first! The more you practice writing small pieces of code with these operators, the more natural they will feel. Happy coding!