How to resolve the algorithm Keyboard input/Obtain a Y or N response step by step in the Wren 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 Wren 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 Wren programming language
Source code in the wren programming language
import "io" for Stdin, Stdout
Stdin.isRaw = true // input is neither echoed nor buffered in this mode
System.print("Press Y or N")
Stdout.flush()
var byte
while ((byte = Stdin.readByte()) && !"YNyn".bytes.contains(byte)) {}
var yn = String.fromByte(byte)
System.print(yn)
Stdin.isRaw = false
You may also check:How to resolve the algorithm Interactive programming (repl) step by step in the Ursa programming language
You may also check:How to resolve the algorithm Truth table step by step in the 8080 Assembly programming language
You may also check:How to resolve the algorithm Random number generator (included) step by step in the TI-83 BASIC programming language
You may also check:How to resolve the algorithm Four is magic step by step in the JavaScript programming language
You may also check:How to resolve the algorithm Ackermann function step by step in the Kotlin programming language