Menu: Difference between revisions
Content added Content deleted
Drkameleon (talk | contribs) (added Arturo) |
MaiconSoft (talk | contribs) (Added Delphi example) |
||
Line 693: | Line 693: | ||
> 2 |
> 2 |
||
You chose 'mirror mirror'.</pre> |
You chose 'mirror mirror'.</pre> |
||
=={{header|Delphi}}== |
|||
{{libheader| System.SysUtils}} |
|||
{{Trans|Go}} |
|||
<lang Delphi> |
|||
program Menu; |
|||
{$APPTYPE CONSOLE} |
|||
uses |
|||
System.SysUtils; |
|||
function ChooseMenu(Options: TArray<string>; Prompt: string): string; |
|||
var |
|||
index: Integer; |
|||
value: string; |
|||
begin |
|||
if Length(Options) = 0 then |
|||
exit(''); |
|||
repeat |
|||
writeln; |
|||
for var i := 0 to length(Options) - 1 do |
|||
writeln(i + 1, '. ', Options[i]); |
|||
write(#10, Prompt, ' '); |
|||
Readln(value); |
|||
index := StrToIntDef(value, -1); |
|||
until (index > 0) and (index <= length(Options)); |
|||
Result := Options[index]; |
|||
end; |
|||
begin |
|||
writeln('You picked ', ChooseMenu(['fee fie', 'huff and puff', 'mirror mirror', |
|||
'tick tock'], 'Enter number: ')); |
|||
readln; |
|||
end.</lang> |
|||
{{out}} |
|||
<pre> |
|||
1. fee fie |
|||
2. huff and puff |
|||
3. mirror mirror |
|||
4. tick tock |
|||
Enter number: 5 |
|||
1. fee fie |
|||
2. huff and puff |
|||
3. mirror mirror |
|||
4. tick tock |
|||
Enter number: 2 |
|||
You picked mirror mirror</pre> |
|||
=={{header|Elixir}}== |
=={{header|Elixir}}== |