A program error

hi, all! my compiler doesn't like the "minus" in line 21, it's like:

/home/cristi/NetBeansProjects/RubyApplication3/lib/helic.rb:21:
undefined method `-' for "":String (NoMethodError)

1 require "init.rb"
2
3 shots = 3
4 time = 1
5 speed = 0
6 x=y=1
7 while (shots!=0) do
8 #give entry data
9 puts "let's f*ck da su**er!"
10 puts "give speed:"
11 speed = gets
12 puts "give angle:"
13 angle = gets
14 #processing entry data
15 angle=(Math::PI)/180*angle.to_f
16 xspeed=speed*Math.cos(angle)
17 yspeed=speed*Math.sin(angle)
18 #trajectory's loop
19 while (y>0) do
20 x=xspeed*time
21 y=yspeed*time-4.9*time**2
22 time+=0.01
23
24 #puts "x="+x.to_i.to_s+" y="+y.to_i.to_s
25 screen.fill_rect 0, 0, 640, 480, BGCOLOR
26 screen.draw_circle x, y, 5, SHELLCOLOR
27 screen.flip
28
29 end
30 shots-=1
31 puts "shots remaining"+ shots.to_s
32 end

help, please. thanks!

···

--
Posted via http://www.ruby-forum.com/.

it appears that yspeed is "", which implies speed from gets is not what you expect it to be. puts speed after you gets it and see.

···

On Dec 15, 2009, at 11:38 PM, Teodor Carstea wrote:

speed*Math.sin(angle)

Try to use
speed = gets.to_i at line 11 and
angle = gets.to_i at line 13 to resolve this.

Regards,
Raghav

···

-----Original Message-----
From: teodorcarstea@yahoo.com [mailto:teodorcarstea@yahoo.com]
Sent: Wednesday, December 16, 2009 1:08 PM
To: ruby-talk ML
Subject: a program error

hi, all! my compiler doesn't like the "minus" in line 21, it's like:

/home/cristi/NetBeansProjects/RubyApplication3/lib/helic.rb:21:
undefined method `-' for "":String (NoMethodError)

1 require "init.rb"
2
3 shots = 3
4 time = 1
5 speed = 0
6 x=y=1
7 while (shots!=0) do
8 #give entry data
9 puts "let's f*ck da su**er!"
10 puts "give speed:"
11 speed = gets
12 puts "give angle:"
13 angle = gets
14 #processing entry data
15 angle=(Math::PI)/180*angle.to_f
16 xspeed=speed*Math.cos(angle)
17 yspeed=speed*Math.sin(angle)
18 #trajectory's loop
19 while (y>0) do
20 x=xspeed*time
21 y=yspeed*time-4.9*time**2
22 time+=0.01
23
24 #puts "x="+x.to_i.to_s+" y="+y.to_i.to_s
25 screen.fill_rect 0, 0, 640, 480, BGCOLOR
26 screen.draw_circle x, y, 5, SHELLCOLOR
27 screen.flip
28
29 end
30 shots-=1
31 puts "shots remaining"+ shots.to_s
32 end

help, please. thanks!
--
Posted via http://www.ruby-forum.com/.

Hi,

···

Am Mittwoch, 16. Dez 2009, 16:38:07 +0900 schrieb Teodor Carstea:

hi, all! my compiler doesn't like the "minus" in line 21, it's like:

/home/cristi/NetBeansProjects/RubyApplication3/lib/helic.rb:21:
undefined method `-' for "":String (NoMethodError)

[...]
20 x=xspeed*time
21 y=yspeed*time-4.9*time**2
[...]

Put something like this before line 21 and the cause of the error
is obvious:

  puts [ xspeed, yspeed, time].inspect

Bertram

--
Bertram Scharpf
Stuttgart, Deutschland/Germany
*
Discover String#notempty? at <http://raa.ruby-lang.org/project/step&gt;\.

Zhao Lu wrote:

it appears that yspeed is "", which implies speed from gets is not what
you expect it to be. puts speed after you gets it and see.

The answer is

speed = gets.to_s

puts speed gave integer, but puts xspeed(and yspeed too) gave "". You
were about right. I fell so stupid...

Thanks!

···

--
Posted via http://www.ruby-forum.com/\.

speed = gets.to_s

shit, I had to write

speed = gets.to_f

sorry

···

--
Posted via http://www.ruby-forum.com/\.