unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Label1: TLabel;
    resN: TLabel;
    adatP: TPanel;
    Label4: TLabel;
    EditA: TEdit;
    Label2: TLabel;
    Label3: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    L1: TLabel;
    L2: TLabel;
    L3: TLabel;
    ismetB: TBitBtn;
    BitBtn1: TBitBtn;
    procedure EditAEnter(Sender: TObject);
    procedure EditAKeyPress(Sender: TObject; var Key: Char);
    procedure ismetBClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}
const
  aMin=50;
  aMax=300;
var
  n: Integer=10;
  i,A,sum: Integer;
  Min: Integer= 1000;
  Max: Integer=-1000;
  avg: Extended;

procedure TForm1.EditAEnter(Sender: TObject);
begin
  resN.Caption:=IntToStr(i+1)+'. adat:';
end;

procedure TForm1.EditAKeyPress(Sender: TObject; var Key: Char);
begin
  if (key=#13) and (editA.Text<>'')
    then begin
           A:=StrToInt(editA.Text);
           if (A<aMin) or (A>aMax)
             then Exit; //Kényszerített kilépés

           if (A<Min)
             then Min:=A;
           if (A>Max)
             then Max:=A;
           sum:=sum+A;
           i:=i+1;
           if (i=n)
            then begin
                   avg:=sum/n;
                   L1.Caption:=IntToStr(Min)+' cm';
                   L2.Caption:=IntToStr(Max)+' cm';
                   L3.Caption:=FloatToStr(avg)+' cm'; //Valós számból csinál szövegest
                   adatP.Show;
                   ismetB.SetFocus;
                   editA.Enabled:=false;
                 end
            else begin
                   resN.Caption:=IntToStr(i+1)+'. adat:';
                   editA.SelectAll;
                 end;
         end;
end;

procedure TForm1.ismetBClick(Sender: TObject);
begin
  i:=0;
  sum:=0;
  Min:=1000;
  Max:=-1000;
  editA.Enabled:=True;
  editA.Clear;
  editA.SetFocus;
  adatP.Hide;
end;

end.
