program Firma_a_platy;

uses crt;

const MaxP = 50;

type Pracovnik = record
                   Jmeno : string;
                   Plat : Real;
                 end;

var Firma : array[1..MaxP]of Pracovnik;
    PocetP : Integer;
    Prikaz : char;

procedure NovyPracovnik;
begin
  writeln('Prazdne jmeno ukonci vstup.');
  repeat
    PocetP := PocetP + 1;
    with Firma[PocetP] do
    begin
      write('Jmeno : ');
      readln(Jmeno);
      if Jmeno <> '' then
      begin
        write('Plat : ');
        readln(Plat);
      end;
    end;
  until (Firma[PocetP].Jmeno = '') or (PocetP = MaxP);
  if Firma[PocetP].Jmeno = '' then PocetP := PocetP - 1;
end;

procedure VypoctiPrumer;
var Pocet : integer;
    PomPlat : real;
begin
  PomPlat := 0;
  Pocet := 0;
  repeat
    Inc(Pocet);
    PomPlat := PomPlat + Firma[Pocet].Plat;
    with Firma[Pocet] do
      writeln(Jmeno,' (prumer : ',Plat:8:2,')');
  until Pocet = PocetP;
  writeln('Prumerny plat vsech ',PocetP,' zamestnancu cini ',(PomPlat/PocetP):12:2,' Kc,');
end;

procedure Hlavni_nabidka;
begin
  textbackground(0);
  clrscr;
  textcolor(lightred);
  gotoxy(18,6); writeln('Program na demonstraci cyklu repeat - until');
  gotoxy(13,7); writeln('Zjisteni prumerneho mesicniho platu zamestnancu firmy');
  gotoxy(28,8); writeln('David Padrta  -  IVT 3');
  textcolor(lightred);
  gotoxy(16,11); writeln('様様様様様様様様様様様様様様様様様様様様様様様');
  textcolor(white);
  gotoxy(16,13); writeln('Nacteni zamestnancu a platu : ');
  gotoxy(16,14); writeln('Vypocteni prum. platu firmy : ');
  textcolor(lightred);
  gotoxy(16,16); writeln('様様様様様様様様様様様様様様様様様様様様様様様');
  textcolor(white);
  gotoxy(16,18); writeln('Ukonceni programu           :  ');
  textcolor(lightgreen);
  gotoxy(47,13); writeln('zmackni N nebo n');
  gotoxy(47,14); writeln('zmackni P nebo p');
  gotoxy(47,18); writeln('zmackni K nebo k');
end;

BEGIN
  clrscr;
  PocetP := 0;
  repeat
    Hlavni_nabidka;
    Prikaz := readkey;
    writeln;
    case Prikaz of
      'n', 'N' : begin
                   textcolor(white);
                   clrscr;
                   NovyPracovnik;
                   writeln;
                   writeln('Stiskni ENTER ...');
                   readln;
                 end;
      'p', 'P' : begin
                   textcolor(white);
                   clrscr;
                   VypoctiPrumer;
                   writeln;
                   writeln('Stiskni ENTER ...');
                   readln;
                 end;
    end;
  until Prikaz in ['k','K'];
END.