
Untitled
By: a guest on
Jun 16th, 2012 | syntax:
None | size: 0.91 KB | hits: 19 | expires: Never
Try and Catch In Pascal
Function GetMenuChoice : Integer;
Var
OptionChosen : Integer;
Begin
Write('Please enter your choice: ');
Readln(OptionChosen);
If (OptionChosen < 1) Or ((OptionChosen > 4) And (OptionChosen <> 9))
Then
Begin
Writeln;
Writeln('That was not one of the allowed options. Please try again: ');
End;
GetMenuChoice := OptionChosen;
End;
Function GetMenuChoice : Char;
Var
OptionChosen : Char;
Begin
repeat
Write('Please enter your choice: ');
Readln(OptionChosen);
If not (OptionChosen in ['1'..'4', '9'])
Then
Begin
Writeln;
Writeln('That was not one of the allowed options. Please try again: ');
End;
until OptionChosen in ['1'..'4', '9'];
GetMenuChoice := OptionChosen;
End;
GetMenuChoice := Ord(OptionChosen) - 48;
GetMenuChoice := Ord(OptionChosen) - Ord('0');