Reputation: 21
Here are the rules of a simple game:
2 players a and b hide their right hands behind their backs. Each chooses to hold a certain number of fingers from 0 to 5 always behind their backs. Both players show their hands at the same time. If the sum of the numbers of fingers shown is a pair, player a wins, otherwise player b wins. The problem is determining the winner by the computer
I've tried this programming in Turbo Pascal but they keep showing the ":" expected but ";" found or the "operand type doesn't match operator"
Program parity;
var nbr1;nbr2,remainder:integer;
begin
read(nbr1,nbr2);
tot:=nbr1+nbr2;
remainder:=tot mod 2;
if remainder=0 then begin write('winner is A')
end
else write('winner is B');
end.
Upvotes: 1
Views: 98
Reputation: 36506
First, let's clean up your code formatting.
program parity;
var
nbr1; nbr2, remainder : integer;
begin
read(nbr1, nbr2);
tot := nbr1 + nbr2;
remainder := tot mod 2;
if remainder = 0 then
begin
write('winner is A')
end
else
write('winner is B');
end.
Your line nbr1; nbr2, remainder : integer;
has an extra terminator so your compiler sees it as thought you'd written:
nbr1;
nbr2, remainder : integer;
It thinks you're missing a type on the declaration of nbr1
, but I strongly suggest you just typoed when writing: nbr1, nbr2, remainder : integer;
Upvotes: 1