Recent

Author Topic: Different results with same code under different IDEs  (Read 1785 times)

lxst

  • Newbie
  • Posts: 1
Different results with same code under different IDEs
« on: January 26, 2015, 06:21:00 pm »
Hi, I tried to compile and run following code under Lazarus and FPC IDE and it gave me different results. On the following input. Do anybody know why?
Code: [Select]
program ps12;
var Soubor: Text;
var max:real;
var i,j:integer;
var pole:array [1..10000] of real;
var nalezeno,dvazaznamy:boolean;

begin
assign(Soubor, 'vstup.txt');
reset(Soubor);
i:=0;
max := -1E1000;
dvazaznamy:=false;
{write(max);}

repeat
Begin
nalezeno:=false;
for j:=1 to i-1 do
begin
if (pole[j]=pole[i]) then
begin
nalezeno:=true;
dvazaznamy:=true;
{write(pole[j]);}
end;
end;

if (nalezeno and (pole[i] > max)) then
begin
max:=pole[i];
end;

i:=i+1;
Read(Soubor,pole[i]);

End
until EOF(Soubor);

if (dvazaznamy) then
begin
write(max:16:4);
end
else
begin
write('Zadny prvek se v seznamu neopakuje.');
end;

close(Soubor);
read(max);
end.
older version of code where error occurred for first time:
Code: [Select]
program ps12;
var Soubor: Text;
var max:real; var i,j:integer;
var pole:array [1..10000] of real;
var nalezeno,dvazaznamy:boolean;

begin
assign(Soubor, 'vstup.txt');
reset(Soubor);
i:=1;
max := -1E1000;
dvazaznamy:=false;
{write(max);}
While (true) do
Begin
Read(Soubor,pole[i]);
if(EOF(Soubor)) then begin break;
end;
nalezeno:=false;
for j:=1 to i-1 do
begin
if (pole[j]=pole[i]) then begin nalezeno:=true;
dvazaznamy:=true;
{write(pole[j]);}
end;
end;
if (nalezeno and (pole[i] > max)) then begin max:=pole[i];
end;
i:=i+1; End;
if (dvazaznamy) then begin write(max:16:4);
end else begin write('Zadny prvek se v seznamu neopakuje.');
end;
close(Soubor);
read(max);
end.
« Last Edit: January 26, 2015, 11:24:32 pm by lxst »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8112
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Different results with same code under different IDEs
« Reply #1 on: January 26, 2015, 06:52:07 pm »
It's the same here. One thing you have to watch out is the default syntax mode in both IDE. Lazarus defaults to ObjFPC (in compiler options, not source), FPIDE defaults to FPC. That could change the mapping of integer identifier (read the docs).

morfrei

  • Newbie
  • Posts: 1
Re: Different results with same code under different IDEs
« Reply #2 on: January 27, 2015, 12:03:43 am »
Older version really doesn't work as it should. Maybe the read() or EOF() function behaves from some reason differently... %)