How to ask for numerica input

F

Fred Ige

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

what command do I use?
 
D

David A. Black

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
 
B

Bertram Scharpf

Hi,

Am Freitag, 25. Sep 2009, 11:12:37 +0900 schrieb David A. Black:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top