[Lazarus] Valladolid Programming Contest simple test fails at compile?

Mehmet Erol Sanliturk sanliturk at ttmail.com
Fri Mar 27 00:24:14 CET 2009


On Thursday 26 March 2009 06:47:45 pm Mehmet Erol Sanliturk wrote:
> On Thursday 26 March 2009 05:16:32 pm Thierry Coq wrote:
> >  >> TEST PROGRAM
> >
> > program Test1;
> >
> > var
> >   i, j : integer; //input data
> >   k, l : integer; //interval
> >   m    : integer; //index
> >   maxCycles : integer; //max number of cycles for the interval
> >   Cycles: integer;
> >
> > // This function computes the number of cycles for the 3N+1 algorithm.
> > function FindCycles(const value: integer):integer;
> > begin
> >   result := 1;
> >   if value > 1 then
> >   begin
> >     if (value mod 2) > 0 then
> >       result := 1+FindCycles(3*value+1)
> >     else
> >       result := 1+FindCycles(value div 2);
> >   end;
> > end;
> >
> > // main program
> > begin
> >   repeat
> >     // get the input interval
> >     readln(i,j);
> >     k := i;
> >     l := j;
> >     if j<i then
> >     begin
> >       k := j;
> >       l := i;
> >     end;
> >
> >     //iterating over each element
> >     maxCycles := 0;
> >     for m := k to l do
> >     begin
> >       Cycles := FindCycles( m);
> >       if Cycles > maxCycles then
> >         maxCycles := Cycles;
> >     end;
> >
> >     //write the results
> >     writeln(i,' ',j,' ', maxCycles);
> >
> >   until eof;
> > end.
> >
> > << END OF TEST PROGRAM
> > _______________________________________________
>
> At until eof , there should be a file variable name as eof ( FN )
> where FN may be
>
> var FN : Text ;
> or
> var FN : File ... ;
>
> 
>
>

I am sorry that the error is NOT the above .
I compiled the program . It is giving error to name result within function
FindCycles as Identifier not found .

If a variable as
var result : integer ;

is defined it is compiled correctly with a warning 

Function result does not seem to be set .

Insertion of statement 

FindCycles := result ;

is removing warning statement .


Thank you very much .

 Mehmet Erol Sanliturk












More information about the Lazarus mailing list