티스토리 뷰

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
















'Back-end' 카테고리의 다른 글

[루비] Hash  (0) 2018.12.22
[루비] 배열과 반복  (0) 2018.12.21
[루비] 메서드 생성  (0) 2018.12.21
[루비] 루비 숫자 다루고 변환 메서드  (0) 2018.12.21
[루비] 다양한 문자열 함수  (0) 2018.12.07
댓글