Menu: Difference between revisions

Content added Content deleted
(→‎{{header|D}}: Fix type mismatch)
Line 783: Line 783:


=={{header|D}}==
=={{header|D}}==
<syntaxhighlight lang="d">import std.stdio, std.conv, std.string, std.array, std.typecons;
<syntaxhighlight lang="d">
import std.stdio, std.conv, std.string, std.array, std.typecons;


string menuSelect(in string[] entries) {
string menuSelect(in string[] entries) {
Line 805: Line 806:
"> ".write;
"> ".write;
immutable input = readln.chomp;
immutable input = readln.chomp;
immutable choice = validChoice(input, entries.length - 1);
immutable choice = validChoice(input, cast(int) (entries.length - 1));
if (choice.isNull)
if (choice.isNull)
"Wrong choice.".writeln;
"Wrong choice.".writeln;
Line 817: Line 818:
"mirror mirror", "tick tock"];
"mirror mirror", "tick tock"];
writeln("You chose '", items.menuSelect, "'.");
writeln("You chose '", items.menuSelect, "'.");
}
}</syntaxhighlight>
</syntaxhighlight>

{{out}}
{{out}}
<pre>Choose one:
<pre>
Choose one:
0) fee fie
0) fee fie
1) huff and puff
1) huff and puff
Line 825: Line 829:
3) tick tock
3) tick tock
> 2
> 2
You chose 'mirror mirror'.</pre>
You chose 'mirror mirror'.
</pre>

=={{header|Delphi}}==
=={{header|Delphi}}==
{{libheader| System.SysUtils}}
{{libheader| System.SysUtils}}