How to resolve the algorithm Keyboard input/Obtain a Y or N response step by step in the QB64 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 QB64 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 QB64 programming language

Source code in the qb64 programming language

WHILE INKEY$ <> "": WEND '                                  Flushes keyboard buffer.
PRINT "Do you want to continue? (Y/N)"
DO
    k$ = UCASE$(INKEY$) '                                   Forces key response to upper case.
LOOP UNTIL k$ = "Y" OR k$ = "N"
PRINT "You pressed " + CHR$(34) + k$ + CHR$(34) + "." '     CHR$(34) prints quotation marks.


  

You may also check:How to resolve the algorithm Almost prime step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Amicable pairs step by step in the Scala programming language
You may also check:How to resolve the algorithm Averages/Root mean square step by step in the V (Vlang) programming language
You may also check:How to resolve the algorithm Last letter-first letter step by step in the C++ programming language
You may also check:How to resolve the algorithm Anagrams step by step in the FreeBASIC programming language