Pascal重复标识符

时间:2015-01-02 15:11:50

标签: pascal

program Noname4;

  function minutes (Amin, Bmin :integer) : integer;

  function time (Aval, Bval :integer) : integer;
  begin
    if (0 <= Aval) and (Bval < 24) then
      time :=Bval - Aval;
    if (0 <= Amin) and (Bmin < 60) then
      minutes :=Bmin - Amin;
  end;

 var Aval, Amin, Bval, Bmin, n , x , i , y :integer;
   duom, rez : text; 
 begin
   readln(Aval, Amin, Bval, Bmin );
   writeln(time(Aval, Bval));
   writeln(minutes(Amin, Bmin));
   readln;
   assign(duom, 'Duomenys2.txt');
   Reset(duom);
   Readln(duom, n );
   assign(rez, 'rezultatai2.txt');
   rewrite(rez);

   for i := 1 to n do
   begin
     Readln(duom, Aval, Amin, Bval, Bmin);
     x := time(Aval, Bval);
     y := minutes (Amin, Bmin);
     writeln(rez, x);
     writeln(rez, y);
   end;
   close(duom);
   close(rez);
 end.

您好,我收到错误(重复的标识符,已在第2行中定义的标识符)。它在(duom,rez:text;)行中显示为红色。无法找出原因


program Noname4;

function minutes (Amin, Bmin :integer) : integer;
function time (Aval, Bval :integer) : integer;
begin
  if (0 <= Aval) and (Bval < 24) then
    time :=Bval - Aval;
  if (0 <= Amin) and (Bmin < 60) then
    minutes :=Bmin - Amin;
end;
var Aval, Bval, n , x , i , y :integer;
  duom, rez : text;
begin
  assign(duom, 'Duomenys2.txt');
  Reset(duom);
  Readln(duom, n );
  assign(rez, 'Rezultatai2.txt');
  rewrite(rez);
  for i := 1 to n do
  begin
    Readln(duom, Aval, Bval, Amin, Bmin);
    x := time(Aval, Bval);
    y := minutes(Amin, Bmin);
    writeln(rez, x);
    writeln(rez, y);
  end;
  close(duom);
  close(rez);
end;

begin
end.

我做了你说的,程序现在工作正常,除了它没有在'Rezultatai2.txt'文件中写出答案。

1 个答案:

答案 0 :(得分:1)

变化:

var Aval, Amin, Bval, Bmin, n , x , i , y :integer;
duom, rez : text;

为:

var Aval, Bval, n , x , i , y :integer;
duom, rez : text;

它们已被定义为传递到分钟函数的变量