Dear Sir,
I have got a serious problem to understanding of the answer.
The question is:
Create the first half of a game of rock, paper, scissors. Ask the user for R,P or S. Get the computer to generate 0,1 or 2. Now convert the computer's number to R, P or S using a case statement. Tell the user wht the computer picked.
The following is my answer:
program RPS5;
{$APPTYPE CONSOLE}
uses
SysUtils,
ourcrt;
var
Computer : integer;
Choice, Move : char;
begin
randomize;
repeat
writeln('Rock(R), Paper(P), Scissors(S)');
readln(Choice);
until (Choice = 'R') or (Choice = 'P') or (Choice = 'S');
case Choice of
'R': writeln('You have chosen Rock');
'P': writeln('You have chosen Paper');
'S': writeln('You have chosen Scissors');
end;
Computer:= random (2);
case Computer of
0: begin writeln('Computer have chosen Rock');
Move:='R';
if Move=choice then begin Writeln('Draw') end
else
if Choice='S' then begin Writeln ('You lose') end
else writeln('You win') end;
1: begin writeln('Computer have chosen Paper');
Move:='P';
if Choice=Move then begin Writeln('Draw') end
else
if Choice='R' then begin Writeln ('You lose') end
else writeln('You win') end;
2: begin writeln('Computer have chosen Scissors');
Move:='S';
if Choice=Move then begin Writeln('Draw') end
else
if Choice='P' then begin Writeln ('You lose') end
else writeln('You win') end;
end;
readln;
end.
I know that user can choose R, P or S and computer generate 0,1 or 2. But could you tell me why 'if Choice='S' then begin Writeln ('You lose')', ...
Cheers,