Calculator
A menu-driven calculator that remembers its history.
๐งฉ Problem statement
A menu-driven calculator that remembers its history. Design it completely in pseudocode first: plan the data, split the work into functions, write the logic, dry-run it and test it.
๐ Requirements
- Addition
- Subtraction
- Multiplication
- Division
- History
๐ฅ Inputs
- Two numbers
- The operation (+, -, *, /)
๐ค Outputs
- The result
- The list of past calculations
๐ Rules
- Division by zero shows a friendly message
๐ง Constraints
- Numbers can be decimals
๐งญ Suggested approach
- Restate the problem in your own words
- List the data you must remember (variables, lists, maps)
- Write one FUNCTION per feature
- Write the main program that calls them
- Dry-run with the Run button
- Test normal cases and edge cases
๐ง Required concepts
- Variables
- Conditions
- Loops
- Lists
Design your solution here. Use Run to dry-run it step by step and Run tests to check it. Hints unlock one at a time โ try on your own first!
๐งช Edge cases to test
- Empty input
- Very large values
- Repeated or duplicate entries
๐ Complexity analysis
Each calculation does a fixed amount of work, so it is O(1). Keeping a history list of n calculations uses O(n) memory.
๐ Solution walkthrough (open after youโve tried!)
We give each operation its own branch in one CALCULATE function. The division branch checks for zero before dividing, because dividing by zero is undefined. The main program only takes the inputs and displays the result โ so the logic stays in one tidy place. To add history, create an empty list before the loop and ADD each result TO it.
๐ Challenge extensions
- Add a feature of your own
- Make it work for 10ร more data โ what changes?