unit toss;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  Tgame = class(TForm)
    coin1: TEdit;
    coin2: TEdit;
    toss: TButton;
    done: TButton;
    outcome: TLabel;
    procedure doneClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure tossClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  game: Tgame;

implementation

{$R *.DFM}

procedure Tgame.doneClick(Sender: TObject);
begin
  close
end;

procedure Tgame.FormCreate(Sender: TObject);
begin
  randomize
end;

procedure Tgame.tossClick(Sender: TObject);
{c1 and c2 are the temporary values used to store the coin results
 TRUE is a head, FALSE is a TAIL}

var c1, c2   : boolean;
    throw    : byte;

begin
  {toss first coin}
  throw := random(50);
  c1 := throw < 25;
  if c1
     then coin1.text := 'HEAD'
     else coin1.text := 'TAIL';

  {now toss second coin}
  throw := random(50);
  c2 := throw < 25;
  if c2
     then coin2.text := 'HEAD'
     else coin2.text := 'TAIL';

  {now decide on outcome}
  if c1 xor c2
     then outcome.caption := 'ODDS'        {coins are different}
     else begin
            outcome.caption := 'EVENS ';   {coins are the same}
            if c1
               then outcome.caption := outcome.caption + 'HEADS'
               else outcome.caption := outcome.caption + 'TAILS'

          end
end;

end.