unit str;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Button2: TButton;
    Edit2: TEdit;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  n,m,l,s:longint;
implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  randomize;
  s:=strtoint(edit2.Text);
  n:=random(s)+1;
  l:=0;
  showmessage(' Число сгенерировано ');
  form1.ActiveControl:=edit1;
end;

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if key=#13 then begin
    m:=strtoint(edit1.Text);
    if m<n then begin
      showmessage(' Число больше ');
      edit1.Text:='';l:=l+1;
    end;
    if m>n then begin
      showmessage(' Число меньше ');
      edit1.Text:='';l:=l+1;
    end;
    if m=n then begin
      showmessage(' Правильно ! Числдо попыток = '+inttostr(l));
      l:=0;
      edit1.Text:='';l:=l+1;
    end;
  end;

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  halt;
end;

end.
