RosettaCodeData/Task/Menu/Modula-2/menu.mod2

61 lines
1.5 KiB
Plaintext

MODULE Menu;
FROM InOut IMPORT WriteString, WriteCard, WriteLn, ReadCard;
FROM STextIO IMPORT ReadChar, SkipLine;
FROM CharClass IMPORT IsNumeric, IsControl, IsWhiteSpace;
CONST StringLength = 100;
MenuSize = 4;
TYPE String = ARRAY[0..StringLength-1] OF CHAR;
PROCEDURE MenuF(): String;
VAR
menu : ARRAY[0..MenuSize] OF String;
inp : CHAR;
selection, index : CARDINAL;
BEGIN
menu[1] := "fee fie";
menu[2] := "huff and puff";
menu[3] := "mirror mirror";
menu[4] := "tick tock";
selection := 0;
WHILE selection=0 DO
FOR index := 1 TO HIGH(menu) DO
WriteString("[");
WriteCard( index,1);
WriteString( "] ");
WriteString( menu[index]);
WriteLn;
END;(*of FOR*)
inp := '';
WriteString("Choose what you want : ");
ReadChar(inp);
SkipLine;
IF IsNumeric(inp) THEN
CASE inp OF
'1' : selection := 1 |
'2' : selection := 2 |
'3' : selection := 3 |
'4' : selection := 4 |
ELSE ;
selection := 0;
END;
IF (selection <= HIGH(menu)) AND (selection > 0) THEN
RETURN menu[selection];
END (*of IF*)
ELSIF IsWhiteSpace(inp) OR IsControl(inp) THEN
RETURN "";
END;
END;
END MenuF;
BEGIN
WriteString(MenuF());
WriteLn;
END Menu.