Historical updating oE prompt_number, Revision 1


include console.e 
namespace console 
public function prompt_number(sequence prompt, sequence range) 

prompts the user to enter a number and returns only validated input.

  1. st : is a string of text that will be displayed on the screen.
  2. s : is a sequence of two values {lower, upper} which determine the range of values that the user may enter. s can be empty, {}, if there are no restrictions.

An atom, in the assigned range which the user typed in.


If puts cannot display st on standard output, or if the first or second element of s is a sequence, a runtime error will be raised.

If user tries cancelling the prompt by hitting Control+Z, the program will abort as well, issuing a type check error.


As long as the user enters a number that is less than lower or greater than upper, the user will be prompted again.

If this routine is too simple for your needs, feel free to copy it and make your own more specialized version.

Example 1:
age = prompt_number("What is your age? ", {0, 150}) 
Example 2:
t = prompt_number("Enter a temperature in Celcius:\n", {}) 
See Also:

puts, prompt_string

Not Categorized, Please Help


Quick Links

User menu

Not signed in.

Misc Menu