1

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.
Tom Brunberg
  • 20,312
  • 8
  • 37
  • 54
  • You need to look really carefully for the wrong character in the code. But don't blindly trust the error message. – Tom Brunberg Dec 18 '22 at 21:13
  • 1
    Isn't it this `var nbr1;nbr2,remainder:integer;1 should be `var nbr1, nbr2, remainder:integer;`. Improving your code formatting would help spot issues.. – John Easley Dec 18 '22 at 22:42

1 Answers1

1

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;

Chris
  • 26,361
  • 5
  • 21
  • 42