Thursday, 19 September 2013

How can i know if a variable is a number or a letter with Pascal?

How can i know if a variable is a number or a letter with Pascal?

I'm trying to make a (very) little code to determine whether a given
variable x is a number or a letter. It has to be done by hand without
things like type(x) -assuming there is such thing Pascal-.
My plan was to verify x is not a number one by one, then i wrote this:
(*let ischar be a boolean and let x be a letter or a number.*)
for i:=0 to 9 do
begin
if (x=i) then
ischar = false;
end;
if ischar then
write('x is a number!');
else
write('x is a letter');
I was hoping that the test "x=i" would return false if x is a letter, but
here i don't even get to compile because of the following error: "Got
char, expected long int". It seems that i can't compare x and i, i knew
that but i tought that under that circumstances if would return false. Is
there another way to do this 'by hand'?

No comments:

Post a Comment