As a side note to the original post: I ran the program as posted, and it works fine, but if I type in "1a" as the input, it will get into an infinite loop and eventually run out of memory. It takes a quite long time, since it's outputting the string "Enter a number or -1 to end..." many many times before it fails (at least on my machine).
--
Mats