-
-
Save d0ppler/f7ab7df326aae21e4f21 to your computer and use it in GitHub Desktop.
This file contains 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
def calculator | |
puts "\tGreetings humanoid, im the Calculator.\n\tEnter 'q' to quit.\n\n\tsyntax: [value] [operator] [value]\n" | |
while true | |
prompt = '>> ' | |
print prompt | |
str = gets.chomp.split(" ") # splits input into array | |
return if str[0] == 'q' | |
operand1 = str[0].to_i | |
operand2 = str[2].to_i | |
operator = str[1].to_sym | |
case operator | |
when :+ then puts operand1 + operand2 | |
when :- then puts operand1 - operand2 | |
when :* then puts operand1 * operand2 | |
when :/ then puts operand1 / operand2 | |
when :% then puts operand1 % operand2 | |
else | |
puts "invalid input" | |
end | |
end | |
end | |
if __FILE__ == $0 | |
calcudator | |
end | |
puts "Okay :( , bye!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment