Author Message

I am new at Pascal programming, and was wondering if any of you could help
me with a lone of code.

I am trying to get the following line to work -

if (e1 + e2) > 21 and x1 = 1 then e1 := 1;

Why won't this work?  Is there another solution to this?

Thanks,
JoeSmith

Wed, 18 Jun 1902 08:00:00 GMT

Quote:

> I am new at pascal programming, and was wondering if any of you could help
> me with a lone of code.
> I am trying to get the following line to work -
> if (e1 + e2) > 21 and x1 = 1 then e1 := 1;
> Why won't this work?  Is there another solution to this?

You're missing some parentheses; you want

if (e1 + e2 > 21) and (x1 = 1) then e1 := 1;

The "and" operator has higher precedence than "relational operators" such as
<, >, = etc. So the compiler tries to evaluate "21 and x1" as a Boolean
expression and, of course, fails.

--
______________________________________________________________________
The Scarlet Manuka,      |        Nitpickers' Party motto:
Pratchett Quoter At Large,  |  "He who guards his lips guards his
First Prophet of Bonni, is:  |  soul, but he who speaks rashly will

______________________________|_______________________________________

Wed, 18 Jun 1902 08:00:00 GMT
Some more parenthesis would help a lot...;)

TXAS, Comando Lagarto.

Quote:

> I am new at pascal programming, and was wondering if any of you could help
> me with a lone of code.

> I am trying to get the following line to work -

> if (e1 + e2) > 21 and x1 = 1 then e1 := 1;

> Why won't this work?  Is there another solution to this?

> Thanks,
> JoeSmith

Wed, 18 Jun 1902 08:00:00 GMT

Write like this: If ((e1+e2)>21) And (x1=1) Then e1: =1
Note If you assign a value to a variable.Like e1:=1 then it is : =
if you make a conditional statement.Like (e1+e2)>21 then it is only =
You can make as many conditions as you like.Just do Like (...) And (...) Or
(....)...

Quote:

> I am new at pascal programming, and was wondering if any of you could help
> me with a lone of code.

> I am trying to get the following line to work -

> if (e1 + e2) > 21 and x1 = 1 then e1 := 1;

> Why won't this work?  Is there another solution to this?

> Thanks,
> JoeSmith

Wed, 18 Jun 1902 08:00:00 GMT

 Page 1 of 1 [ 4 post ]

Relevant Pages