Dear Sir,
Could you tell me what is (are) wrong of the following answer:-
Question:-
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,1or 2. Now convert the computer’s number to R, P or S using a case statement. Tell the user what the computer picked. Draw an Activity Diagram first.
Can you finish the rock, paper, scissors game? One solution to working out who won is the following:
check whether it was a draw ie player=computer
else check if the player won ie (player = R and computer = S) or (player = S and computer = P) or (player = P and computer = R)
else the only other alternative is that the computer won.
You should be able to this with one nested if
program RPSii;
{$APPTYPE CONSOLE}
uses
SysUtils,
ourcrt;
var
Computer : integer;
Choice, compChar : char;
begin
randomize;
repeat
writeln('Welcome to play the game of 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 (3);
case Computer of
0: writeln('Computer have chosen Rock');
1: writeln('Computer have chosen Paper');
2: writeln('Computer have chosen Scissors');
end;
if ((Choice='R') and (compChar='S')) or ((Choice='P') and (compChar='R')) or ((Choice='S') and (compChar='P')) then
begin
writeln('You win');
end
else
if ((Choice='R') and (compChar='R')) or ((Choice='P') and (compChar='P')) or ((Choice='S') and (compChar='S')) then
begin
writeln('You draw');
end
else
writeln('You loss');
readln;
end.
Could you tell me what is (are) wrong of the above answer because when I execute the program, it always give me the wrong answer 'you loss'.