Recent

Author Topic: Incompatiple types  (Read 2047 times)

ransaked

  • New Member
  • *
  • Posts: 10
Incompatiple types
« on: November 28, 2015, 01:59:57 pm »
Hi, again.

Now I have a question about Incompatible Types message. I know what it means but idk why it appears in a program I have integers ONLY. Take a look please and explain me where the number becomes Extended and why? Thanks a lot.

Code (It may have more errors):
var
 ta,l,p,i,j,d2ta,d3ta,d2l,d3l,d2f,d3f,nf,nta,nl:integer;
 f,g:text;
begin
 assign(f,'daruri.in');
 reset(f);
 read(f,ta);
 readln(f,l);
 close(f);
if frac(ta/2)=0 then inc(d2ta)
else if frac(ta/3)=0 then inc(d3ta)
 else for i:=4 to 32000 do
   if frac(ta/i)<>0 then continue
   else break;
if frac(l/2)=0 then inc(d2l)
else if frac(l/3)=0 then inc(d3l)
 else for j:=4 to 32000 do
   if frac(l/j)<>0 then continue
   else break;
if d2ta<=d2l then if d2ta=0 then d2f:=1 else d2ta:=d2f
 else d2l:=d2f;
if d3ta<=d3l then if d3ta=0 then d3f:=1 else d3ta:=d3f
 else d3l:=d3f;
if i<=j then i:=nf
 else j:=nf;
p:=d2f*d3f*nf;
nta:=ta/p;
nl:=l/p;
 assign(g,'daruri.out');
 rewrite(g);
 writeln(g,p);
 write(g,nta);
 write(g,nl);
 close(g);
end.

Error message:
s(27,8)Error: Incompatible types: got "Extended" expected "SmallInt"
s(28,6)Error: Incompatible types: got "Extended" expected "SmallInt"
s(41)Fatal: There were 2 errors compiling module, stopping
s(0)Fatal: Compilation aborted
                                                                      Thanks again, nice community. HaVe A nIcE dAy :) :) :) :)

jwdietrich

  • Hero Member
  • *****
  • Posts: 1232
    • formatio reticularis
Re: Incompatiple types
« Reply #1 on: November 28, 2015, 02:28:25 pm »
It is no surprise that you get this error.

Pascal's "/" operator delivers floating point values. If you want to assign the results of a division to an integer than you have to use the div operator.

In your case it would me more appropriate, however, to define the variables as real or extended.
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 2.2.6 | FPC 3.2.2 | PPC, Intel, ARM | macOS, Windows, Linux

ransaked

  • New Member
  • *
  • Posts: 10
Re: Incompatiple types
« Reply #2 on: November 28, 2015, 02:41:43 pm »
Thx i'll try...

 

TinyPortal © 2005-2018