Skip to content

Instantly share code, notes, and snippets.

@matt297
Last active November 15, 2016 01:20
Show Gist options
  • Save matt297/84c0f106123e342f81089ee3fa612b77 to your computer and use it in GitHub Desktop.
Save matt297/84c0f106123e342f81089ee3fa612b77 to your computer and use it in GitHub Desktop.
Calculator Challenge

Calculator Challenge

You have been tasked with creating a program that runs in the command line (bash). The program should ask for 2 numbers, a mathematical operator, and then execute the operation on the two numbers.

How It Works

  • Can be run using bash (i.e. ruby yourfile.rb)
  • Asks the user to input a number (i.e. 10)
  • Asks the user to input another number (i.e. 5)
  • Asks the user to input a mathematical operator (i.e. +)
  • Outputs the the result of the computation (i.e. 15.0)
  • The user should have the option to perform another computation, or exit the program

Technical Requirements

  • Only accept integers (and error gracefully if the user inputs anything else)
  • Only accept valid mathematical operators (and error gracefully if something else is inputted)
  • Output floats (numbers with decimals)
  • Have a class called Calculator
  • Your class should have instance methods that perform each type of computation (i.e. addition, subtraction, etc)
  • Only create once instance of the Calculator class (no matter how many computations the user does)

Sample

Enter a number:
5
Enter another number:
5
Enter a mathematical operator:
+
5 + 5 = 10
Would you like to perform another calculation? (y/n)
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment