How to ask for numerica input

I am trying to make a simple temperature converter, and I want to ask
for F temperature (numerical value)

what command do I use?

···

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

Hi --

I am trying to make a simple temperature converter, and I want to ask
for F temperature (numerical value)

what command do I use?

The bread-and-butter way to get keyboard input is with gets:

   print "Enter a number: "
   line = gets

and then, since line is a string:

   num = line.to_i

You can get fancier with error-checking, etc., but that's the basic
idea.

David

···

On Fri, 25 Sep 2009, Fred Ige wrote:

--
David A. Black, Director
Ruby Power and Light, LLC (http://www.rubypal.com)
Ruby/Rails training, consulting, mentoring, code review
Book: The Well-Grounded Rubyist (http://www.manning.com/black2\)

Hi,

···

Am Freitag, 25. Sep 2009, 11:12:37 +0900 schrieb David A. Black:

On Fri, 25 Sep 2009, Fred Ige wrote:

I am trying to make a simple temperature converter, and I want to ask
for F temperature (numerical value)

what command do I use?

  print "Enter a number: "
  line = gets
  num = line.to_i

You can get fancier with error-checking, etc., but that's the basic
idea.

This does the error checking:

   num = Integer line

Bertram

--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de