Doubt about "A night at the movies"


#1

Hi i´m new on programming and i want to learn/know if this code:

movies = {
StarWars: 4.8,
Divergent: 4.7
}

puts "What would you like to do? "

choice = gets.chomp

case choice
when “add”
puts "What movie would you like to add? "
title = gets.chomp.to_sym
puts "What rating does the movie have? "
rating = gets.chomp.to_i

if movies[title].nil?
movies[title]= rating
puts “Got it!”
else
puts “That movie already exists daugh”
end

when “update”
puts “What movie are you searching for?”
title=gets.chomp.to_sym

if movies[title].nil?
puts “Sorry dude, that movie isn’t in the hash”
else
puts “Ok, please write your rating of that movie”
movies[title]= gets.chomp.to_i
end

when “display”
movies.each do |movie,rate|
puts “#{movie}: #{rate}”
end
when “delete”
puts “Deleted!”
else
puts “Error!”
end
#end of the code

can be converted to continue doing actions(same, other) despite of doing 1 action and then have to start over the program.
Thank you very much!
pd: my english is far to be well but i try to be the more clear as possible

link of excercise = https://www.codecademy.com/courses/learn-ruby/lessons/a-night-at-the-movies/exercises/delete?action=resume_content_item


#2

Consider writing the whole thing inside a loop, but be sure to give yourself a way to stop the loop (add a quit option).


#3

Oh that´s a really good idea, thank you!! i think i will need to use the loop do and break syntax. I´m not sure but i will try that way .


#4

Man thank you very much i tried with loop do and break if and it worked well ! :DDDD


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.