Challenge 3

🧮

Calculator

Open in Code Editor or Copy Instructions
...solutions at bottom of page...

Create a calculator program - ask the user to enter 2 real numbers and an operator (+, -, *, /, **, DIV, MOD) - perform the correct operation based on their input and display the full calculation and answer

Examples:

For example, if the user entered 5, 6 and *, then the output would be

5 * 6 = 30

Extension:

After getting their initial answer, allow them to enter another operator and value and perform that on the original answer. If the original answer was 30 and they then entered * and 2, their new answer would be 60 - this process could happen indefinitely until they entered 'C' (cancel) like on a typical calculator, which would reset the state of the program

Solutions

IGCSE 0478 / O-Level 2210 A-Level 9618