Programs to Debug: Number 4

We suggest that you inspect this program to see if you can spot the errors before attempting to compile it in Delphi or Lazarus. Make the necessary changes so that each program will compile and achieve the stated purpose. Our pages on common programming errors may help you.

program RandomBits;
{$APPTYPE CONSOLE}
{This program should select a 0 or 1 at random ten
times then output a count of the number of occurrences
of each digit.  There are two deliberate errors.}
uses
  SysUtils;
var
  i, Count0, Count1  : integer;
  RandomNo : 0..1;
begin
  randomize;
  Count0 := 0;
  Count1 := 0;
  for i = 1 to 10 do
  begin
    RandomNo := Random(2);
    if RandomNo = 0 then
    begin
      Count0 := Count0 + 1;
    end
    else;
    begin
      Count1 := Count1 + 1;
    end;
  end;
  writeln('0 Count: ',Count0);
  writeln('1 Count: ',Count1);
  readln;
end.
Programming - a skill for life!

Spot the deliberate errors