0
print"Do you want to calculate your invoice? Please enter Yes(Y) or No(N)... "
calculate_cont = ""
while calculate_cont = gets.chomp()
calculate_cont.to_s
calculate_cont.upcase!
case calculate_cont
when "Y", "YES"
<calculations>
print "Do you wish to continue? "
when "N", "NO"
puts "Thank you! Press Enter to exit!"
gets()
exit()
else
puts "Error: #{calculate_cont} is not a valid entry!
puts "Please Enter a valid response! Yes(Y) or No(N)"
print "Do you wish to continue? "
end
end
當用戶輸入除YES或NO之外的其他內容時,它將顯示他使用#{calculate_cont}輸入的文本。我如何告訴用戶,如果用戶只需使用#{calculate_cont}進行輸入,他就會輸入「Nothing」?可以做到嗎?ruby show#{}當沒有輸入任何內容時
感謝