Back-end
[루비] if/elsif/else 문
jhkang-dev
2018. 12. 21. 17:54
if condition
end
if condition
else
end
if condition
elsif
else
end
def multiploy(first, second)
first.to_f * second.to_f
end
def divide(first, second)
first.to_f / second.to_f
end
def mod(first, second)
first.to_i % second.to_i
end
puts "Where do you want to do? 1) multiply 2) divide 3) subtract 4) find remainder"
prompt = gets.chomp
puts "enter in your first number"
first_number=gets.chomp
puts "Enter in your second number"
second_number=gets.chomp
if prompt == '1'
puts "You have chosen ~~"
result = multiply(first_number, second_number)
elsif prompt == '2'
puts "You have chosen to divide"
result = divide(first_number, second_number)
else
puts "You have made an invalid choice"
end