Ruby newbie here.
I'm trying to write a very simple calculator where I store the numbers in variables and check if the user input for the operator is included in the array of possible operators, if it is then it should perform the calculation using those variables
Is there a way I can get the result from combining theses 3 variables? Right now is throwing me the error "String can't be coerced into Integer"
puts "enter a number!"
num1 = gets.chomp().to_i
puts "enter an operator!"
op = gets.chomp()
puts "enter another number"
num2 = gets.chomp().to_i
operators = ["+", "*", "-", "/"]
result = nil
if operators.include?(op)
result = num1 + "#{op}" + num2
else
puts "enter a valid operator"
end
puts result