# Calculator in Ruby

I have created a calculator in Ruby. I am using Ruby 2.1.0. I'm fairly sure that someone will be able to improve this, as I am quite new to Ruby.

puts "Welcome to Calc"
puts ""

puts "Please enter the first number"
n1 = gets.to_i()
puts ""

puts "Please enter the second number"
n2 = gets.to_i()
puts ""

subtract = n1 - n2
multiply = n1 * n2
divide = n1 / n2
power = n1 ** n2
sqrt1 = Math.sqrt(n1)
sqrt2 = Math.sqrt(n2)

puts "#{n1} + #{n2} = #{add}"
puts "#{n1} - #{n2} = #{subtract}"
puts "#{n1} * #{n2} = #{multiply}"
puts "#{n1} / #{n2} = #{divide}"
puts "#{n1} ** #{n2} = #{power}"
puts "#{n1} √ = #{sqrt1}"
puts "#{n2} √ = #{sqrt2}"

gets()


One thing you forgot to check was if n2 is 0 and n1 is non zero, in which case the answer is either undefined or a signed infinity.
• In addition: divide on integers is a modulo division. If it is intented to use the modulo division, then I would expect both values using divmod. Or you have to convert one value to float value. – knut Apr 6 '15 at 18:02