Can't convert Fixnum into String


When I enter a movie title that already exists in the hash, it prompts me to enter the new rating, and then it tells me that it "can't convert Fixnum into String". I am a little confused and would love some help. Thanks.

movies = {Incredibles: 5
puts "What would you like to do?"
choice = gets.chomp
case choice
when "add"
    puts "What is the title of the movie you would like to add?"
    title = gets.chomp
if movies[title.to_sym].nil?
    puts "What is the rating of the moive you would like to add?"
    rating = gets.chomp
    movies[title.to_sym] = rating.to_i
    puts "Added #{title} to our database with the rating #{rating}!"
    puts "This movie is already in our database!"
when "update"
    puts "What is the title of the movie you want to update?"
    title = gets.chomp
if movies[title.to_sym].nil?
    puts "There is no movie in our database with that title! You should add it!"
    puts "What would you like to change the rating to?"
    rating = gets.chomp
    movies[title.to_sym] = rating.to_i
    print "The movie #{title} now has a rating of " + movies[title.to_sym]
when "display"
    puts "Movies!"
when "delete"
    puts "Deleted!"
    puts "Error!"


That pinpoints where in the code it's happening, so you would have a look at that part, consider what it was you wanted to do there, and then either fix it or first find out how to do that action


I have trying out different things for a while, and haven't been able to fix the problem. Any other hints/advice?


That's how you do it. There are no hints to give, it's no mystery.

"can't do it" doesn't take you forward, that's giving up. Instead you need to figure out what stops you and solve that before continuing. Why are you not able to do it?

That's problem solving in a nutshell. Identify the problem, ask yourself what stops you from fixing it, fix that, and repeat. This may go on for a while if you're missing information. And sometimes you gotta ask, but when you do you gotta ask about the current problem, not "can't do it" because that leads no-where!

You'll also want to be more deliberate than "try a few things". Decide what you need and aim straight at it. The first thing you need is to find out exactly which operation is crashing.


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