Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 16th, 2012  |  syntax: None  |  size: 0.91 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Try and Catch In Pascal
  2. Function GetMenuChoice : Integer;
  3.   Var
  4.     OptionChosen : Integer;
  5.   Begin
  6.     Write('Please enter your choice: ');
  7.     Readln(OptionChosen);
  8.     If (OptionChosen < 1) Or ((OptionChosen > 4) And (OptionChosen <> 9))
  9.       Then
  10.         Begin
  11.           Writeln;
  12.           Writeln('That was not one of the allowed options.  Please try again: ');
  13.         End;
  14.     GetMenuChoice := OptionChosen;
  15.   End;
  16.        
  17. Function GetMenuChoice : Char;
  18. Var
  19.   OptionChosen : Char;
  20. Begin
  21.   repeat
  22.     Write('Please enter your choice: ');
  23.     Readln(OptionChosen);
  24.  
  25.     If not (OptionChosen in ['1'..'4', '9'])
  26.       Then
  27.         Begin
  28.           Writeln;
  29.           Writeln('That was not one of the allowed options.  Please try again: ');
  30.         End;
  31.   until OptionChosen in ['1'..'4', '9'];
  32.   GetMenuChoice := OptionChosen;
  33. End;
  34.        
  35. GetMenuChoice := Ord(OptionChosen) - 48;
  36.        
  37. GetMenuChoice := Ord(OptionChosen) - Ord('0');