Domanda

I have written a code with 8 procedures and 2 functions.

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 looks like the following:

10

3

2

4

1

5

7

8

9

10

8

When I run the program five errors occur:

 - 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"

Why it happens and how can I fix it?

Thanks in advance.

È stato utile?

Soluzione

In pascal, all functions must be declared before you use them. Move the functions Test_Up, Test_Down and FindBigger higher up the file.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top