Forum: Ruby-Forum.com How to pass user input data to variables to solve formula

53d0ab2f26ae207b65797ad020e4264d?d=identicon&s=25 Can Le (math75)
on 2009-02-09 16:35
I known that to compute series of number, we have to

puts #{(2+19)/3}
we have answer = 7

How to enter inputs from keyboard to do math, for variables as number 2
above, such as

puts #{(var +19)/3}

I tried puts var, printf #{var}, var=STDIN, STDOUT.puts var, all without
error but no answer!

It is working OK, if I have a given var with a value number:
var=2
puts #{(var +19)/3}
I will have answer = 7

Otherwise, if we put:

STDOUT.puts var
puts #{(var +19)/3}

error is: undefined local variable or method

Thank You
Fd2f3880f3484eb1ba81a757d4f899e9?d=identicon&s=25 gopi In (sarma)
on 2009-03-12 06:09
Can Le wrote:
> I known that to compute series of number, we have to
>
> puts #{(2+19)/3}
> we have answer = 7
>
> How to enter inputs from keyboard to do math, for variables as number 2
> above, such as
>
> puts #{(var +19)/3}
>
> I tried puts var, printf #{var}, var=STDIN, STDOUT.puts var, all without
> error but no answer!
>
> It is working OK, if I have a given var with a value number:
> var=2
> puts #{(var +19)/3}
> I will have answer = 7
>
> Otherwise, if we put:
>
> STDOUT.puts var
> puts #{(var +19)/3}
>
> error is: undefined local variable or method
>
> Thank You



print "Enter a value?"
var = gets
puts  (var.to_i+19)/3

try this, i hope it helps you.

Thank you
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.