From: Prasanth Ravi Date: 2010-03-10T04:06:58+09:00 Subject: Re: convert s to i, then + 1 Mike Peltzer wrote: > Hi all, I am very to new to ruby and am having trouble writing a very > simple program: basically i just want to ask for an integer then return > the integer +1 > here is my code: > --------------------------------------------------- > puts 'what\'s your favorite number?' > var1 = 1 > num = gets.chomp > puts 'well ' + num.to_i + ' + var1 is better' > > ------------------------ > > when I run it, this is the error i get: > --------------------------------------- > what's your favorite number? > 3 > ri20min.rb:5:in `+': can't convert Fixnum into String (TypeError) > from ri20min.rb:5:in `
' > --------------------------------------- > I realize this is laughable, but I am struggling with the concept, any > help is greatly appreciated. puts 'what\'s your favorite number?' puts "well #{gets.chomp.to_i + 1} is better" same as the others suggested.. -- Posted via http://www.ruby-forum.com/.