Problem with to_sym


#1

whats wrong with this one?
It says problem with to_sym

code:-

mmovies = {
Lord_of_the_Rings: 4,
Harry_Potter: 4,
Jurassic_Park: 3
}
puts "What would you like to do?"
puts "-- Type 'add' to add a movie."
puts "-- Type 'update' to update a movie."
puts "-- Type 'display' to display all movies."
puts "-- Type 'delete' to delete a movie."

choice = gets.chomp

case choice
when "add"
puts "What movie would you like to add?"
title = gets.chomp
if movies[title.to_sym].nil?

puts "What's the movie rating? (Type a number 0 to 4.)"
rating = gets.chomp
movies[title.to_sym] = rating.to_i
puts "#{title} has been added with a rating of #{rating}."
else
puts "That movie already exists! Its rating is #{movies[title.to_sym]}."
end

when "update"
puts "Which movie would you like to update?"
title = gets.chomp
if movies[title].nil?
puts "#{title} is not stored in the hash."
else
puts "Please type in the new rating for #{title}:"
new_rating = gets.chomp
movies[title.to_sym] = new_rating.to_i
end

when "display"
movies.each { |movie,rating| puts "#{movie}: #{rating}"}

when "delete"
puts "which movie to delete?"
text=gets.chomp
if movies[title.to_sym].nil?
puts "error! this movie doesnt exist in library"
else
movies.delete(title)
end
end


A Night at the Movies: Delete
#2

This looks like the root of the problem... mm...


#3

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