Keyboard input/Obtain a Y or N response: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 236:
return 0;
}</lang>
 
=={{header|C++}}==
Windows specific
<lang cpp>#include <conio.h>
#include <iostream>
 
using namespace std;
 
int main()
{
char ch;
_cputs( "Yes or no?" );
do
{
ch = _getch();
ch = toupper( ch );
} while(ch!='Y'&&ch!='N');
 
if(ch=='N')
{
cout << "You said no" << endl;
}
else
{
cout << "You said yes" << endl;
}
return 0;
}
</lang>
 
=={{header|C sharp}}==
Line 303 ⟶ 274:
}
}</lang>
 
=={{header|C++}}==
Windows specific
<lang cpp>#include <conio.h>
#include <iostream>
 
using namespace std;
 
int main()
{
char ch;
_cputs( "Yes or no?" );
do
{
ch = _getch();
ch = toupper( ch );
} while(ch!='Y'&&ch!='N');
 
if(ch=='N')
{
cout << "You said no" << endl;
}
else
{
cout << "You said yes" << endl;
}
return 0;
}
</lang>
 
=={{header|Clojure}}==
Line 408:
<pre>Enter Y or N: abcN
Response: N</pre>
 
=={{header|EGL}}==
{{Works with|EDT}}
{{Works with|RBD}}
<lang EGL>handler YesOrNoHandler type RUIhandler{initialUI =[ui], onConstructionFunction = start}
 
ui Div { };
const KEY_N int = 78;
const KEY_Y int = 89;
function start()
document.onKeyDown = d_onKeyDown;
end
function d_onKeyDown(e Event in)
case (e.ch)
when (KEY_N)
ui.innerText = "N pressed.";
when (KEY_Y)
ui.innerText = "Y pressed.";
end
e.preventDefault();
end
end</lang>
 
=={{header|Elm}}==
Line 481 ⟶ 510:
 
printf(1,"Your response was %s\n",key)</lang>
 
=={{header|EGL}}==
{{Works with|EDT}}
{{Works with|RBD}}
<lang EGL>handler YesOrNoHandler type RUIhandler{initialUI =[ui], onConstructionFunction = start}
 
ui Div { };
const KEY_N int = 78;
const KEY_Y int = 89;
function start()
document.onKeyDown = d_onKeyDown;
end
function d_onKeyDown(e Event in)
case (e.ch)
when (KEY_N)
ui.innerText = "N pressed.";
when (KEY_Y)
ui.innerText = "Y pressed.";
end
e.preventDefault();
end
end</lang>
 
 
=={{header|F_Sharp|F#}}==
Line 1,019 ⟶ 1,018:
output :yorn
end</lang>
 
 
=={{header|Mathematica}}==
<lang Mathematica>CreateDialog[TextCell["Yes or no?[Y/N]"],
NotebookEventActions -> {
"KeyDown" :> Switch[ToUpperCase@CurrentValue["EventKey"],
"Y", Print["You said yes"]; DialogReturn[],
"N", Print["You said no"]; DialogReturn[]
]}];</lang>
 
=={{header|M2000 Interpreter}}==
Line 1,134 ⟶ 1,124:
UseUIForm
</lang>
 
=={{header|Mathematica}}==
<lang Mathematica>CreateDialog[TextCell["Yes or no?[Y/N]"],
NotebookEventActions -> {
"KeyDown" :> Switch[ToUpperCase@CurrentValue["EventKey"],
"Y", Print["You said yes"]; DialogReturn[],
"N", Print["You said no"]; DialogReturn[]
]}];</lang>
 
=={{header|Microsoft Small Basic}}==
Line 1,266 ⟶ 1,264:
print "\nYou typed: $key\n";
</lang>
=={{header|Perl 6}}==
<lang perl6>my $TTY = open("/dev/tty");
 
sub prompt-char($prompt) {
ENTER shell "stty raw -echo min 1 time 1";
LEAVE shell "stty sane";
 
print $prompt;
$TTY.read(1).decode('latin1');
}
 
say so prompt-char("Y or N? ") ~~ /:i y/;</lang>
 
=={{header|Phix}}==
Line 1,452 ⟶ 1,438:
(stty tty-settings)
</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
<lang perl6>my $TTY = open("/dev/tty");
 
sub prompt-char($prompt) {
ENTER shell "stty raw -echo min 1 time 1";
LEAVE shell "stty sane";
 
print $prompt;
$TTY.read(1).decode('latin1');
}
 
say so prompt-char("Y or N? ") ~~ /:i y/;</lang>
 
=={{header|REXX}}==
Line 1,554:
[N] msg$ = "You entered [N]o" : goto [loop]
</lang>
 
=={{header|Rust}}==
{{libheader|Ncurses}}
10,333

edits