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,

And could you tell me why '0: begin writeln('Computer have chosen Rock')' as well??

Cheers,

Tony

Hi Turbomen.
On my land,hungary,there is a rule.
PAPER stronger then ROCK
ROCK stronger then SCISSORS
SCISSORS stronger then PAPER
think of it as precedence rule... :D
by the way, computer:=Random(2); will always 1 or 0 cause

Generates random numbers within a specified range.
Unit : System
Category: random number routines
syntax: function Random [ ( Range: Integer) ];
In Delphi code, Random returns a random number within the range 0 <= X < Range. If Range is not specified, the result is a real-type random number within the range 0 <= X < 1.
To initialize the random number generator, add a single call Randomize or assign a value to the RandSeed variable before making any calls to Random.

so change your code like
computer:=Random(3); the result will 0 or 1 or 2 :D

case skeleton is
Case var_name Of
0:command;
1:command;
2:command;
Else command;
End;
But if you want to put more than one command,then you have to put them between begin..end;
Case var_name Of
0:Begin
command1;
command2;
End;
1:command;
....
....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.