| | |
Could you tell me what is wrong of my answer?
Thread Solved |
•
•
Join Date: Feb 2009
Posts: 93
Reputation:
Solved Threads: 0
Dear Sir / Madam,
The following is the game of Rock, Paper, Scissors. But I don't know why computer is always choose Rock.
My Answer:-
program RPS5;
{$APPTYPE CONSOLE}
uses
SysUtils,
ourcrt;
var
Computer : integer;
Choice, Move : char;
begin
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;
sleep (10000);
end.
Could you tell me what is wrong of my answer,
Cheers,
The following is the game of Rock, Paper, Scissors. But I don't know why computer is always choose Rock.
My Answer:-
program RPS5;
{$APPTYPE CONSOLE}
uses
SysUtils,
ourcrt;
var
Computer : integer;
Choice, Move : char;
begin
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;
sleep (10000);
end.
Could you tell me what is wrong of my answer,
Cheers,
Here is the fixed version of your program 

delphi Syntax (Toggle Plain Text)
(* Dear Sir / Madam, The following is the game of Rock, Paper, Scissors. But I don't know why computer is always choose Rock. My Answer:- *) Program RPS5; {$APPTYPE CONSOLE} Uses SysUtils; var Computer : integer; Choice, Move : char; Begin //main 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;//case Randomize; (* <-- you forget about randomize,not? *) Computer:= Random(2); Case Computer of 0: Begin WriteLn('Computer have chosen Rock'); Move:='R'; If (Move=choice) Then Begin Writeln('Draw') End //'if' move Else Begin If Choice='S' Then Begin WriteLn ('You lose') End //'if' choice Else WriteLn('You win'); End;//else End;//case 0 1: Begin WriteLn('Computer have chosen Paper'); Move:='P'; If (Choice=Move) Then Begin Writeln('Draw'); End Else Begin If (Choice='R') Then Begin Writeln ('You lose'); End Else writeln('You win'); End; End;//case 1 2: Begin WriteLn('Computer have chosen Scissors'); Move:='S'; If (Choice=Move) Then Begin Writeln('Draw'); End Else Begin If (Choice='P') Then Begin Writeln ('You lose'); End Else writeln('You win'); End; End;//case 2 End;//case main //sleep(10000); ReadLn; //I put this line,waiting for press the enter button End.//of main program (* -=Note By FlamingClaw=- I dont know your 'ourcrt',so I put it out Sorry for formatting your program,but now already readable...to me. You forget about randomize!!! -=Created By FlamingClaw=- -=2009.04.04=- *)
Last edited by FlamingClaw; Apr 4th, 2009 at 10:48 am.
Be a good part of the community.Don't be ungrateful.
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
![]() |
Similar Threads
- My CD-RW plays but won't burn. What could be wrong?? Help Please? (Storage)
- Double variable type, unexpected answer (C++)
- Can't figure out where my ACM sollution gives wrong answer. (C++)
- Something wrong with my code, why Junk character appears? (C)
- C++ Macros - help please (C++)
- Is Redirect Bad for Business? (Search Engine Optimization)
- Iexplore problem (Web Browsers)
- when i use a proxy, it say's port closed. could it be (Networking Hardware Configuration)
Other Threads in the Pascal and Delphi Forum
- Previous Thread: Please help me again
- Next Thread: Add the elements of an array together
| Thread Tools | Search this Thread |





