Menu: Difference between revisions
Content added Content deleted
(→{{header|D}}: Fix type mismatch) |
|||
Line 792: | Line 792: | ||
try { |
try { |
||
immutable n = input.to!int; |
immutable n = input.to!int; |
||
return typeof(return)((n >= 0 && n <= nEntries) ? n : -1); |
return typeof(return)((n >= 0 && n <= nEntries) ? n : -1); |
||
} catch (Exception e) // Very generic |
} catch (Exception e) // Very generic |
||
Line 805: | Line 806: | ||
writefln(" %d) %s", i, entry); |
writefln(" %d) %s", i, entry); |
||
"> ".write; |
"> ".write; |
||
immutable input = readln.chomp; |
immutable input = readln.chomp; |
||
immutable choice = validChoice(input, cast(int) (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 821: | ||
immutable items = ["fee fie", "huff and puff", |
immutable items = ["fee fie", "huff and puff", |
||
"mirror mirror", "tick tock"]; |
"mirror mirror", "tick tock"]; |
||
writeln("You chose '", items.menuSelect, "'."); |
writeln("You chose '", items.menuSelect, "'."); |
||
} |
} |