Pascal: Validating Integer Input

program ex7(input,output);
var a,b,c,d : integer;
begin
  repeat
    writeln ('Enter an integer between 100 and 999');
  
  readln (a);
    if (a < 100) then writeln ('Number too small');
    if (a >999) then writeln ('Number too big');
    until (a >99) and (a<1000);
  repeat
    writeln ('Enter an integer between 100 and 999');
  
  readln (b);
    if (b < 100) then writeln ('Number too small');
    if (b >999) then writeln ('Number too big');
    until (b >99) and (b<1000);
  c:=a * b;
  writeln (c);
  d:= a div b;
  writeln (d);
  readln;
end.

To ensure numbers entered match criteria (100-999, 3 digits) we use two techniques:

This error trapping does not prevent the user from entering non-numeric data.

Back to questions