How to resolve the algorithm Keyboard input/Obtain a Y or N response step by step in the FreeBASIC programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Keyboard input/Obtain a Y or N response step by step in the FreeBASIC programming language
Table of Contents
Problem Statement
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.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Keyboard input/Obtain a Y or N response step by step in the FreeBASIC programming language
Source code in the freebasic programming language
' FB 1.05.0 Win64
While InKey <> "" : Wend '' flush keyboard buffer
Print "Do you want to continue y/n : ";
Dim answer As String
Do
answer = LCase(Inkey)
Loop Until answer = "y" OrElse answer = "n"
Print answer '' echo response to console
If answer = "y" Then
Print "OK, continuing"
Else
Print "OK, finishing"
End If
Sleep
You may also check:How to resolve the algorithm RSA code step by step in the Julia programming language
You may also check:How to resolve the algorithm Echo server step by step in the Mathematica/Wolfram Language programming language
You may also check:How to resolve the algorithm Day of the week step by step in the AppleScript programming language
You may also check:How to resolve the algorithm Repeat a string step by step in the OpenEdge/Progress programming language
You may also check:How to resolve the algorithm Sorting algorithms/Quicksort step by step in the Oberon-2 programming language