Simple program with error message

My task is to write a full name greeting program (from how to program
eBook by Chris pine)

This is the error msg I’m getting: full_greeting.rb:7: syntax error,
unexpected $end …and your surname is’ + s_name +
^

Any help would be much appreciated. :slight_smile:

post the full code you wrote.


From: Joshua P. [email protected]
To: [email protected]
Sent: Monday, November 25, 2013 9:26 AM
Subject: simple program with error message

My task is to write a full name greeting program (from how to program
eBook by Chris pine)

This is the error msg I’m getting: full_greeting.rb:7: syntax error,
unexpected $end …and your surname is’ + s_name +
^

Any help would be much appreciated. :slight_smile:

full code I wrote:

puts ‘Hello there, whats your first name?’
f_name = gets.chomp
puts 'Excellent ’ + f_name + ‘now what is your middle name?’
m_name = gets.chomp
puts ‘Thank you, and finally, what is your surname?’
s_name = gets.chomp
puts ‘So youre first name is’ + f_name+ ‘your middle name is’

That code, despite spelling mistakes and missing spaces, works. No
errors.

On Mon, Nov 25, 2013 at 4:47 PM, Joshua P. [email protected] wrote:

full code I wrote:

puts ‘Hello there, whats your first name?’
f_name = gets.chomp
puts 'Excellent ’ + f_name + ‘now what is your middle name?’
m_name = gets.chomp
puts ‘Thank you, and finally, what is your surname?’
s_name = gets.chomp
puts ‘So youre first name is’ + f_name+ ‘your middle name is’

There’s something missing in there, I think. In the error you showed
in the first post it said:

full_greeting.rb:7: syntax error, unexpected $end …and your surname
is’ + s_name +

and that sentence (“and your surname is…”) is missing from your
code. Do you have any weird character in there or something?

Jesus.

ok this is my fault, the program I posted above was incomplete. The
error message i’m getting for the full code is below is: syntax error,
unexpected $end

puts ‘Hello there, whats your first name?’
f_name = gets.chomp
puts 'Excellent ’ + f_name + ‘now what is your middle name?’
m_name = gets.chomp
puts ‘Thank you, and finally, what is your surname?’
s_name = gets.chomp
puts ‘So youre first name is’ + f_name+ ‘your middle name is’ + m_name +
‘and your surname is’ + s_name +

If the code you posted above is correct, then you have to remove the ‘+’
after s_name. Ruby is throwing the error because your program
unexpectedly
ended with a character that requires some input to follow. Can’t end a
line
with ‘+’. Someone else may be able to better explain what the error
means
in detail.

On Mon, Nov 25, 2013 at 5:02 PM, Joshua P. [email protected] wrote:

puts ‘So youre first name is’ + f_name+ ‘your middle name is’ + m_name +
‘and your surname is’ + s_name +

The last ‘+’ should not be there.

Jesus.

Jesus is right. However, I know from having read Chris P.'s book
myself
that he is not up to that part yet. Joshua, you’ll see string
interpolation
used in the future and it is definitely much better to use, but for now
you
may not want to confuse yourself. Pine goes over it very well later in
the
book.

On Mon, Nov 25, 2013 at 11:07 AM, Jess Gabriel y Galn <

On Mon, Nov 25, 2013 at 5:04 PM, Jess Gabriel y Galn
[email protected] wrote:

s_name = gets.chomp
puts ‘So youre first name is’ + f_name+ ‘your middle name is’ + m_name +
‘and your surname is’ + s_name +

The last ‘+’ should not be there.

It’s better to use string interpolation:

puts ‘Hello there, whats your first name?’
f_name = gets.chomp
puts ‘Excellent #{f_name} now what is your middle name?’
m_name = gets.chomp
puts ‘Thank you, and finally, what is your surname?’
s_name = gets.chomp
puts “So, your first name is #{f_name}, your middle name is #{m_name}
and your surname is #{s_name}”

Jesus.

On Mon, Nov 25, 2013 at 5:09 PM, Jason K. [email protected]
wrote:

Jesus is right. However, I know from having read Chris P.'s book myself
that he is not up to that part yet. Joshua, you’ll see string interpolation
used in the future and it is definitely much better to use, but for now you
may not want to confuse yourself. Pine goes over it very well later in the
book.

Ooops, sorry. Didn’t realize that he was following the book and that
string interpolation was covered later.
Joshua, yes, please, follow the book and forget about string
interpolation until later.

Jesus.

Thanks again Joel, Wayne, Jason and Jesus,

especially for putting up with my toddler esq mistakes and problems.
I’ll get better at posting my questions with all the relevant info soon
I promise! This community is so awesome and it’s guys like you that make
it so!

Extremely grateful!! :stuck_out_tongue: