Getting user's input from a menu of choices
- Posted by Caracatsanis Pty Ltd <sunpsych at VIC.OZLAND.NET.AU> Aug 13, 2000
- 463 views
I asked recently, how to code for the situation where the user is presented with a menu consisting of several non mutually exclusive choices... eg MENU OF CHOICES A this B that C other ...or 1 this 2 that 3 other ...and is prompted to enter them (eg A C; or 1 2 3 ) I now realise my question is more about this: 1 if I try to use choice = get(0) to get the input, I have to know beforehand how many choices there'll be, to issue get() the right number of times. Must I ask the user to specify beforehand the number of choices, or else use a sentinel value? 2 if I use choice = gets(0), I get a sequence of ASCII values. Eg if the user's input was... 1 3 2 gets(0) would return {49,51,50,10} After removing choice[4], I don't know how to re-create {1,3,2} I'm particularly interested in ending up with a sequence of numbers, because I want to use them as indices for elements of other sequences Eg: sequence all_choices, choice all_choices = { "up", "down", "right", "left", "stop" } for i = 1 to length(choice) do -- where choice = {1,3,2} index = choice[1] puts(1, all_choices[index]) end for Thanks in advance for any newbie-level solutions. Alex Caracatsanis