找不到标识符

时间:2014-02-19 22:01:19

标签: function pascal identifier freepascal

我编写了一个包含8个程序和2个函数的代码。

program solar;
var
    solararray:array[1..1000000] of longint;
    solartrue:array[1..1000000] of boolean;
    solarnumber:array[1..1000000] of shortint;
    n,counter,counter2,counter3,number,maxn:longint;
    fin,fout:text;

procedure Initialize;
    begin
    assign(fin,'solar.in');
    assign(fout,'solar.out');
    reset(fin);
    rewrite(fout);
    end;

procedure FillArray;
    begin
    read(fin,n);
    for counter:=1 to n-1 do
        read(fin,solararray[counter]);
    close(fin);
    end;

procedure First;
    begin
    if solararray[1] < solararray[2]
    then solartrue[1]:=Test_Up(1)
    end;

procedure Other;
    begin
    for counter:=2 to n-1 do
        begin
        if Test_Up(counter) And Test_Down(counter)
        then solartrue[counter]:=true
        else solartrue[counter]:=false;
        end;
    end;

procedure Last;
    begin
    if solararray[n] > solararray[n-1]
    then solartrue[n]:=Test_Down(n)
    end;

function Test_Up (place : longint) : boolean;
    var
    istrue:boolean;
    begin
    for counter2:=1 to n-1 do
        begin
        if solararray[place] < solararray[counter2]
        then istrue:=true
        else;
            begin
            istrue:=false;
            break;
            end;
        end;
    end;

function Test_Down (place : longint) : boolean;
    var
    istrue:boolean;
    begin
    for counter3:=place-1 downto 1 do
        begin
        if solararray[place] > solararray[counter3]
        then istrue:=true
        else;
            begin
            istrue:=false;
            break;
            end;
        end;
    end;

procedure FindTrues;
    begin
    number:=0;
    for counter:=1 to n do
        begin
        if solartrue[counter]
        then
            begin
            number:=number+1;
            solarnumber[number]:=solararray[counter];
            end
        end;
    end;

procedure Select;
    begin
    if number=0
    then write(fout,'NOT FOUND')
    else FindBigger;
    end;

procedure FindBigger;
    begin
    maxn:=solarnumber[1];
    for counter:=1 to number do
        begin
        if solarnumber[counter] > maxn
        then maxn:=solarnumber[counter]
        end;
        write(fout,maxn);
    end;

begin
    Initialize;
    FillArray;
    First;
    Other;
    Last;
    FindTrues;
    Select;
    close(fout);
    halt(0);
end.

solar.in如下所示:

10

3

2

4

1

5

7

8

9

10

8

当我运行该程序时,会发生五个错误:

 - solar.pas (28,28) Error: Identifier not found "Test_Up"
 - solar.pas (35,13) Error: Identifier not found "Test_Up"
 - solar.pas (35,36) Error: Identifier not found "Test_Down"
 - solar.pas (44,30) Error: Identifier not found "Test_Down"
 - solar.pas (97,17) Error: Identifier not found "FindBigger"

为什么会发生这种情况?我该如何解决?

提前致谢。

1 个答案:

答案 0 :(得分:3)

在pascal中,所有函数必须在之前声明。将函数Test_Up,Test_Down和FindBigger移到文件的上方。