

Task

Obtain a valid   Y   or   N   response from the keyboard.

The keyboard should be flushed, so that any outstanding key-presses are removed, preventing any existing   Y   or   N   key-press from being evaluated.

The response should be obtained as soon as   Y   or   N   are pressed, and there should be no need to press an   enter   key.




integer key
 
puts(1,"Your answer? (Y/N)\n")
while get_key()!=-1 do
end while
 
while 1 do
    key = get_key()
    if key!=-1 and (key = 'Y' or key = 'y' or key = 'N' or key = 'n') then
        exit
    end if
end while
 
printf(1,"Your response was %s\n",key)