From: sto.mar@...
Date: 2012-11-05T23:16:52+09:00
Subject: Re: Simple question
Am 05.11.2012 14:52, schrieb August Y.:
> this block
> def size
> pi=Math::PI
> area=pi*($radus^2)
> volume = 4/3*pi*($radus^3)
> return volume
> return $radus
> return area
> end
>
> Returns this error
> C:/Users/jyoung/objects.rb:20:in `*': true can't be coerced into Float
> (TypeError)
You are trying to multiply with `true' in line 20 of your program.
You could add a line before line 20 with `puts $radius' to see
whether the variable really has the value you think it has.
> pi is defigned and $radus is to.f so what am i missing
you mean to_f ?
Furthermore:
- `^' does not do what you think it does -> bitwise xor!!!
You need to use `**' (3**2 = 9)
- 4/3 is 1 (integer division), you need 4.0 / 3 = 1.3333333
- only the first return statement is executed,
the last two lines are never reached.
You should read up on some basics, see e.g.
.
--