Skip to content

Instantly share code, notes, and snippets.

@wofockham
Last active January 9, 2023 12:18
Show Gist options
  • Save wofockham/2752aa06121df7f3024c to your computer and use it in GitHub Desktop.
Save wofockham/2752aa06121df7f3024c to your computer and use it in GitHub Desktop.

Calculator

Explanation

  • You will be building a calculator. A calculator can perform multiple arithmetic operations. Your function should allow the user to choose which operation is expected, enter in the values to perform the operation on, and ultimately view the result.

Specification:

  • A user should be given a menu of operations
  • A user should be able to choose from the menu
  • A user should be able to enter numbers to perform the operation on
  • A user should be shown the result
  • This process should continue until the user selects a quit option from the menu

Phase 1

  • Calculator functionality
  • Calculator should be able to do basic arithmetic (+,-, *, /)

Phase 2

  • Advanced Calculator functionality
  • Calculator should be able to do basic arithmetic (exponents, square roots)

Bonus

Mortgage Calculator

Calculate the monthly required payment given the other variables as input (look up the necessary variables)

BMI Calculator

Calculate the body mass index (BMI) for an individual, given their height and weight

Trip Calculator

Calculate a trip time and cost given inputs for

  • distance
  • miles per gallon
  • price per gallon
  • speed in miles per hour

Bonus Challenge

Do-It-Yourself Ruby REPL

Try to create your own Ruby REPL (Read Evaluate Print Loop) program.

It should show a prompt, read some Ruby code from the user, evaluate their code, print the result and loop back to the start.

Sample Session

$ ruby repl.rb
Welcome to Ruby REPL
> 2 + 7
9
> "some" + "string"
"somestring"
>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment