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

Content added Content deleted
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 236: Line 236:
return 0;
return 0;
}</lang>
}</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}}==
=={{header|C sharp}}==
Line 303: Line 274:
}
}
}</lang>
}</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}}==
=={{header|Clojure}}==
Line 408: Line 408:
<pre>Enter Y or N: abcN
<pre>Enter Y or N: abcN
Response: N</pre>
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}}==
=={{header|Elm}}==
Line 481: Line 510:


printf(1,"Your response was %s\n",key)</lang>
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#}}==
=={{header|F_Sharp|F#}}==
Line 1,019: Line 1,018:
output :yorn
output :yorn
end</lang>
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}}==
=={{header|M2000 Interpreter}}==
Line 1,134: Line 1,124:
UseUIForm
UseUIForm
</lang>
</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}}==
=={{header|Microsoft Small Basic}}==
Line 1,266: Line 1,264:
print "\nYou typed: $key\n";
print "\nYou typed: $key\n";
</lang>
</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}}==
=={{header|Phix}}==
Line 1,452: Line 1,438:
(stty tty-settings)
(stty tty-settings)
</lang>
</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}}==
=={{header|REXX}}==
Line 1,554: Line 1,554:
[N] msg$ = "You entered [N]o" : goto [loop]
[N] msg$ = "You entered [N]o" : goto [loop]
</lang>
</lang>

=={{header|Rust}}==
=={{header|Rust}}==
{{libheader|Ncurses}}
{{libheader|Ncurses}}