Care to take a minute and help out a newbie? ;) I''ve tried everything I can think of, but I don''t come from a programming background. puts ''What is your first name?'' first_name = gets.chomp puts ''Middle name?'' middle_name = gets.chomp puts ''Last name?'' last_name = gets.chomp puts ''did you know there are '' first_name + middle_name + last_name + ''characters'' puts ''in your name'' + first_name + middle_name + last_name + ''?'' ERROR: ruby length.rb length.rb:7: syntax error, unexpected tIDENTIFIER, expecting $end ...ou know there are '' first_name + middle_name + last_name + ''... Thanks a ton :)
On Aug 7, 5:08 am, kook <rubensantia...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Care to take a minute and help out a newbie? ;) > I''ve tried everything I can think of, but I don''t come from a > programming background. > > puts ''What is your first name?'' > first_name = gets.chomp > puts ''Middle name?'' > middle_name = gets.chomp > puts ''Last name?'' > last_name = gets.chomp > puts ''did you know there are '' first_name + middle_name + last_name + > ''characters''Because if you have a string delimited with '' marks you have to escape any '' you put in the string. Some general info about strings in ruby http://www.devarticles.com/c/a/Ruby-on-Rails/Strings-in-Ruby/ http://www.zenspider.com/Languages/Ruby/QuickRef.html#6 Fred> puts ''in your name'' + first_name + middle_name + last_name + ''?'' > > ERROR: > > ruby length.rb > length.rb:7: syntax error, unexpected tIDENTIFIER, expecting $end > ...ou know there are '' first_name + middle_name + last_name + ''... > > Thanks a ton :)
And this is the corrected program. puts ''What is your first name?'' first_name = gets.chomp puts ''Middle name?'' middle_name = gets.chomp puts ''Last name?'' last_name = gets.chomp full_name = first_name + middle_name + last_name puts ''did you know there are '' + full_name.length.to_s+''characters '' \ ''in your name '' + full_name + ''?'' Is that you need? Sijo -- Posted via http://www.ruby-forum.com/.
kook wrote:> Care to take a minute and help out a newbie? ;) > I''ve tried everything I can think of, but I don''t come from a > programming background.You might like to work through some of the beginning-level tutorials such as Try Ruby, then. And please, ask your general Ruby questions on the Ruby list. They''re off topic for the Rails list.> > puts ''What is your first name?'' > first_name = gets.chomp > puts ''Middle name?'' > middle_name = gets.chomp > puts ''Last name?'' > last_name = gets.chomp > puts ''did you know there are '' first_name + middle_name + last_name + > ''characters'' > puts ''in your name'' + first_name + middle_name + last_name + ''?''Syntax error or no, this program won''t do what you want. You need to learn how to take the length of a string (look at the docs for class String and you''ll find what you need).> > ERROR: > > ruby length.rb > length.rb:7: syntax error, unexpected tIDENTIFIER, expecting $end > ...ou know there are '' first_name + middle_name + last_name + ''... > > Thanks a ton :)You can''t have a string and a variable name next to each other without an operator in between. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.