fork download
  1. Program Example49;
  2.  
  3. { Program to demonstrate the Random and Randomize functions. }
  4.  
  5. Var I,Count,guess : Longint;
  6. R : Real;
  7.  
  8. begin
  9. Randomize; { This way we generate a new sequence every time
  10.   the program is run}
  11. Count:=0;
  12. For i:=1 to 50 do
  13. If Random>0.5 then inc(Count);
  14. Writeln ('Generated ',Count,' numbers > 0.5');
  15. Writeln ('out of 50 generated numbers.');
  16. count:=0;
  17. For i:=1 to 5 do
  18. begin
  19. write ('Guess a number between 1 and 5 : ');
  20. readln(Guess);
  21. If Guess=Random(5)+1 then inc(count);
  22. end;
  23. Writeln ('You guessed ',Count,' out of 5 correct.');
  24. end.
Runtime error #stdin #stdout #stderr 0s 4376KB
stdin
Standard input is empty
stdout
Generated 23 numbers > 0.5
out of 50 generated numbers.
Guess a number between 1 and 5 : 
stderr
./prog: attempt to read past end of Input (error #454 at 402cc9)