Pastey solved
- Posted by _tom (admin) Oct 01, 2015
- 1282 views
Welcome to oE!
Please post in the forum when asking for help. More people will notice then.
The "problem" with gets(STDIN) is that it includes the return key.
sequence s = gets(STDIN) -- enter 5 for example ? s --> { 5, 10 } -- where 10 is the value for the return key
To convert this to a number remove the "10":
s = s[1 .. $-1] -- now convert atom x = convert:to_integer( s ) ? x --> 5
An alternative program would look like this:
include std/console.e atom number = console:prompt_number("Please enter number: ", {} ) atom divisor = console:prompt_number("Please enter divisor: ", {} ) if divisor = 0 then printf(1, "Can't divide by zero!" ) else printf(1, "%d / %d = %d", { number, divisor, number/divisor } ) end if
_tom