I need to calculate odd/even sum, here is what I've got so far:
PROGRAM EvenOddSum;
USES
WinCrt;
VAR
odd, even, x: INTEGER;
BEGIN
WriteLn('Calculation of sum');
WriteLn;
odd := 0;
even := 0;
Write('Enter value(s)');
WHILE x > 0 DO BEGIN
IF x mod 2:= 0 THEN BEGIN
even := even + x;
ELSE
odd := odd + x;
ReadLn(x);
END;
WriteLn;
WriteLn('Even sum is = ', even);
WriteLn('Odd sum is =', odd);
END.
I use freepascal.org compiler and I get this error :
SYNTAX error THEN expected but := found
And I just can't see the problem with this code.
In Pascal, := is the assignment operator. Replace it with = on the line that reads IF x mod 2:= 0 THEN BEGIN.
Also, remove the BEGIN. The result should read:
IF x mod 2 = 0 THEN
It's in here:
IF x mod 2:= 0 THEN BEGIN
The := is used for assignment, use '=' or '==' for comparison.
(Off the top of my head, I don't know if Pascal uses '=', '==', or both for comparisons. One of them should do the trick).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With