From: Gary Wright Date: 2012-01-07T15:53:20+09:00 Subject: Re: "Have your program add one to the number" ? On Dec 18, 2011, at 11:22 PM, Fellipe de Paula wrote: > I'm starting to learn Ruby using the Learn to Program book by Chris > Pine. > > On a mini assignment I need to: > > "Write a program which asks for a person's favorite number. Have your > program add one to the number, then suggest the result as a bigger and > better favorite number. (Do be tactful about it, though.) " > > Here's what I have so far... > > 1 full_name = first_name + ' ' + middle_name + ' ' + last_name > 2 puts full_name + ', ' + 'What\'s your favorite number???' > 3 favorite_number = gets.chomp > 4 new_number = favorite_number.to_i + 1 > 5 puts 'hmmm... What about ' + new_number + '? ' + 'It\'s bigger and > better than yours :)' > > The program runs smoothly until line 4 than it returns the following > error: > > :in `+': can't convert Fixnum into String (TypeError) > > Could you please point my mistake? Are you sure the problem is on line 4? Seems like it is more likely that it is on line 5 where you try to put new_number into a new message. That is where you need to convert it back to a string. Gary Wright