Creating a simple calculator using branching concept in Ruby

Photo by Editors Keys on Unsplash
Preview

Preview

def multiply (num_1, num_2)
num_1.to_f * num_2.to_f
end

def divider (num_1, num_2)
num_1.to_f / num_2.to_f
end

def addition (num_1, num_2)  
num_1.to_f + num_2.to_f
end

def subtraction (num_1, num_2)  
num_1.to_f - num_2.to_f
end

def mod (num_1, num_2)  
num_1.to_f % num_2.to_f
end

puts "Simple calculator"
25.times {print "-"}
puts "Enter the first number"
num_1 = gets.chomp
puts "Enter the second number"
num_2 = gets.chomp
puts "What do you want to do?"
puts "Enter 1 for multiply, 2 for division, 3 for addition, 4 for subtraction, 5 for mod"

user_entry = gets.chomp

if user_entry == "1"  
puts "You've chosen to multiply"  
puts "The multiplication is #{multiply(num_1, num_2)}"

elsif user_entry == "2"  
puts "You've chosen to divide"  
puts "The division is #{divider(num_1, num_2)}"

elsif user_entry == "3"  
puts "You've chosen to addition"  
puts "The addition is #{addition(num_1, num_2)}"

elsif user_entry == "4"  
puts "You've chosen to subtract"  
puts "The substraction is #{subtraction(num_1, num_2)}"

elsif user_entry == "5"  
puts "You've chosen to mod"  
puts "The mod is #{mod(num_1, num_2)}"

else   
puts "Invalid"

end