updating oE prompt_number


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. prompt : is a string of text that will be displayed on the screen.
  2. range : is a sequence of two values {lower, upper} which determine the range of values that the user may enter. It can be empty, {}, if there are no restrictions.

An integer, the value which the user typed in, when within the assigned range.


If prompt is not a printable string, or either element of range is not an atomic value, a runtime error will be raised.

If the user tries cancelling the prompt by hitting Control+Z, the program will abort, issuing a "Stopped" message.

If the user enters a decimal value a type-check failure occurs, but only if the value is within range.


For as long as the user enters a number that is less than lower, or a number 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:
include std/console.e
integer age = prompt_number("What is your age? ", {0, 150}) 
Example 2:
include std/console.e
integer 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