Clueless - 1 year ago 83

Ruby Question

I just wanted to work on one method then replicate it to the rest. which is why one method is really only done. (kinda)

`puts "Welcome to My Calculator! "`

print "Please place in the numbers. "

first_number = gets.to_i

print "Second number. "

second_number = gets.to_i

puts "What operation? "

operation_selection = gets

if(operation_selection == "add")

addition_function

puts"#{result}"

end

def addition_function

result = first_number + second_number

end

def subtraction_function

result = first_number - second_number

end

def divison_function

result = first_number / second_number

end

def multiplication_function

result = first_number * second_number

end

Answer Source

Is this what you want?

```
puts "Welcome to My Calculator! "
print "Please place in the numbers. "
first_number = gets.to_i
print "Second number. "
second_number = gets.to_i
puts "What operation? "
operation_selection = gets.chomp.downcase.to_s
def oper(operation_sel, first_number,second_number)
case operation_sel
when "add"
puts first_number + second_number
when "sub"
puts first_number - second_number
when "div"
puts first_number / second_number
when "mul"
puts first_number * second_number
end
end
oper(operation_selection,first_number,second_number)
```