Last active
August 29, 2015 13:57
-
-
Save jmoon90/9498666 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @number = 0 | |
| print "How much should we add:" | |
| @number + gets.chomp.to_i | |
| puts "> #{@number}" | |
| print "How much should we subtract:" | |
| @number - gets.chomp.to_i | |
| puts "> #{@number}" | |
| print "How much should we multiply:" | |
| @number = gets.chomp.to_i * @number | |
| puts "> #{@number}" | |
| print "How much should we divide:" | |
| @number = @number / gets.chomp.to_i | |
| puts "> #{@number}" | |
| print "Would you like to add again?" | |
| puts answer = gets.chomp | |
| if answer == "yes" | |
| calculator.rb | |
| else | |
| return | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Calculator | |
| def initialize | |
| @number = 0 | |
| end | |
| def add | |
| print "How much should we add:" | |
| n = gets.chomp.to_i | |
| @number = n + @number | |
| puts "> #{@number}" | |
| end | |
| def subtract | |
| print "How much should we subtract:" | |
| n = gets.chomp.to_i | |
| @number = @number - n | |
| puts "> #{@number}" | |
| end | |
| def multiply | |
| print "How much should we multiply:" | |
| n = gets.chomp.to_i | |
| @number = n * @number | |
| puts "> #{@number}" | |
| end | |
| def divide | |
| print "How much should we divide:" | |
| n = gets.chomp.to_i | |
| @number = @number / n | |
| puts "> #{@number}" | |
| end | |
| def repeat | |
| print "Would you like to add again?" | |
| answer = gets.chomp | |
| if answer == "yes" | |
| run_file | |
| else | |
| return | |
| end | |
| end | |
| def run_file | |
| add | |
| subtract | |
| multiply | |
| divide | |
| repeat | |
| end | |
| end | |
| calc = Calculator.new | |
| calc.run_file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment