Function 使用Pascal记录查找最大薪资值

Function 使用Pascal记录查找最大薪资值,function,record,pascal,procedure,turbo-pascal,Function,Record,Pascal,Procedure,Turbo Pascal,我已经编写了一个程序,将关于工人的不同数据填入表中。(姓名、姓氏和薪水) 请帮助我编写一个程序或函数,查找最大工资值和此工作人员的姓名,并将其写入控制台 我能用线圈做吗 program labasix; type firma = record name : string; lastName : string; salary : integer; end; var svitoch : array[1..12] of firma; i : integer; countOf

我已经编写了一个程序,将关于工人的不同数据填入表中。(姓名、姓氏和薪水)

请帮助我编写一个程序或函数,查找最大工资值和此工作人员的姓名,并将其写入控制台

我能用线圈做吗

program labasix;

type firma = record
  name : string;
  lastName : string;
  salary : integer;
end;

var
  svitoch : array[1..12] of firma;
  i : integer;
  countOfWorkers : integer;
begin
  write('Number of workers (not more than 12): ');
  readln(countOfWorkers);
  writeln();

  for i := 1 to countOfWorkers do
    begin
      write('Name: '); readln( svitoch[i].name );
      write('lastName: '); readln( svitoch[i].lastName );
      write('Salary: '); readln( svitoch[i].salary );
      writeln();
    end;

   for i := 1 to countOfWorkers  do
     begin
        { what code must be here ??? }
     end;
end.
一定有这样的事

procedure findMax(x, y, z: integer; var m: integer); 

begin
   if x > y then
      m:= x
   else
      m:= y;
   if z > m then
      m:= z;
end;
但是如何获得xyz值呢


非常感谢你

很明显,你需要查看你现在拥有的员工列表(数组),寻找薪水最高的员工

因此,编写一个函数(而不是过程),将该数组作为参数接受

函数应该将第一个工人的工资存储到一个变量中,然后循环遍历其余工人;如果员工的工资高于您已存储的工资,请将存储的值替换为新的更高的值,然后继续循环。当您到达列表的末尾时,您存储了最高工资,然后从函数返回


提示:您应该使用
Low(YourArray)
作为循环的起点,使用
High(YourArray)
作为循环的停止点,因此,您可以传递给该数组中函数的工人数量没有限制。

这是一个简单的函数,它返回包含数组中薪资最大值的索引。在此之后将其粘贴到代码中:

type firma = record
  name : string;
  lastName : string;
  salary : integer;
end;
这就是功能:

function getmax():integer;
var max:integer;
begin
     max:=1;
     for i:=2 to countOfWorkers do
     begin
         if svitoch[i].salary > svitoch[max].salary then
         max:=i;
     end;
     getmax:=max;
end;
因此,现在您可以在第一个for周期后使用此结构(而不是第二个for周期)赚取最高工资值(和名称)

i:=getmax();
writeln(svitoch[i].name);  {if you want to write in your case}
writeln(svitoch[i].lastName);
writeln(svitoch[i].salary);

你完全不知道该怎么办?@500-内部服务器错误我已经尝试了双循环,我在下面描述了它的过程