Jump to content
A-man

Type Mismatch with constants

Recommended Posts

I have the code

var 
 x: integer;

Const
 W = 512;

begin
 x := W/16;
 writeln(x);
end;

 

the line with x := W/16 throws a type mismatch. I think it has to do with the division, but I'm pretty sure it didnt used to do that before. I also tried using x := int(W/16); and that didn't work either. There is more to my code, this is just the essentials of the scenario. I should note that if I replace the W/16 with 32, the code executes perfectly.

Link to comment
Share on other sites

In math integers are defined as being natural numbers, 0, and negative numbers. Not fractions! I'm no math genius but that is what an integer is (google it).

 

So thus you can't divide the Integer 2 / 3, because that would end up being a fraction. But if you had 2 as a type called Extended which can be a fraction. Then you could do it. DIV is used to divide the number evenly, and I think it rounds either up or down.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...