Madymino
Madymino

Reputation: 1

What is wrong with my Ruby programming code?

This code is supposed to work. But every time I open it on Ruby, Ruby just closes almost immediately because it can't read something in the code. So obviously there's an error(s) in the code but I reviewed everything and couldn't seem to find it. I need some help to get this code working. Thank-you so much in advance!

puts 'Enter the number of the current month using the 12 months per year scale. Ex. January would be 1, February would be 2, March would be 3, etc...'
month=gets.chomp
case month
when '1'..'3'
fee='$45'
when'4'..'5'
fee='$55'
when'7'..'8'
fee='$65'
else
fee='$0.00'
end
puts'The fee to apply for the competition is ' + fee + '.00 when you apply on the date of today, ' + Time.now.to_s +'.'
puts 'If your fee came up as $0.00, then that is because the competition has ended. But do not worry, there is always next year!'
sleep 20

Upvotes: 0

Views: 778

Answers (1)

icktoofay
icktoofay

Reputation: 129139

This is what Ruby tells me the syntax error is:

temp.rb:13: syntax error, unexpected tUPLUS, expecting $end
... of today, ' + Time.now.to_s +'.'

Adding a space between the + and the '.' fixes the syntax error.


You could have figured this out yourself by running Ruby from the command line. I assume you're running Windows. To get to the command prompt, you can press Windows key and R to open the run dialog. From there, you can type in cmd and press enter to open command prompt. You can then use cd to change the current directory and ruby to run your Ruby script (assuming Ruby is in the PATH). Your session might look like this:

C:\Documents and Settings\Madelyn Grewal> cd Desktop

C:\Documents and Settings\Madelyn Grewal\Desktop> ruby myscript.rb
myscript.rb:13: syntax error, unexpected tUPLUS, expecting $end
... of today, ' + Time.now.to_s +'.'

C:\Documents and Settings\Madelyn Grewal\Desktop>

Upvotes: 4

Related Questions