Skip to content

Instantly share code, notes, and snippets.

Created April 9, 2015 06:03
Show Gist options
  • Save anonymous/029ce03a604887665849 to your computer and use it in GitHub Desktop.
Save anonymous/029ce03a604887665849 to your computer and use it in GitHub Desktop.
calc
def calcudator
puts "Greetings humanoid.\nEnter 'q' to quit."
prompt = '>> '
while true
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment