๐Ÿงฎ

Calculator

A menu-driven calculator that remembers its history.

Project 1Beginner

๐Ÿงฉ 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
โœ๏ธ Pseudocode editor ยท dry-run tool ยท test cases

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?

โ† All projects