I need help with loops.
I'm trying to capture the input from the user and determine a hotel's cost for planning a vacation.
I have a problem looping the input so the user can pick another hotel and end the program if the user does not pick any of the keystrokes ("A", "a", "B", "b", "C", "c", "D", or "d"), and then calculate the total cost for hotels.
I came up with this so far:
puts choice = gets.chomp.downcase
puts "For how many nights?"
num=gets.chomp.to_i
puts "Okay...any other hotels?"
puts choice = gets.chomp.downcase
#Hotel Prices
#Hotel A
if (choice== "a" or choice=="A")
cost_2= (num/3)*500 + (num%3)*200
end
#Hotel B
if (choice=="b" or choice=="B")
cost_3= num*250
end
#Hotel C
if (choice=="c" or choice=="C")
cost_4 = (num/3)*700 + (num%3)*300
end
#Hotel D
if (choice== "d" or choice=="D")
cost_5= num*500
end
Kernel#loop.loop do; ..; break if <some condition)>;...; end. You could use (for example)while true;..;endorwhile 1;...; end, butloopis preferred. In some case you may preferwhile(<some condition>);..;endoruntil(<some condition);..;end. One advantage ofloopis that when the loop contains an enumerator that attempts to enumerate beyond its end, causing the enumerator to raise aStopInterationexception,loophandles the exception by breaking out of the loop. See Kernel#loop.