Could you tell me what is wrong of my answer?

Thread Solved

Join Date: Feb 2009
Posts: 93
Reputation: turbomen is an unknown quantity at this point 
Solved Threads: 0
turbomen turbomen is offline Offline
Junior Poster in Training

Could you tell me what is wrong of my answer?

 
0
  #1
Apr 4th, 2009
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,
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 444
Reputation: FlamingClaw will become famous soon enough FlamingClaw will become famous soon enough 
Solved Threads: 106
FlamingClaw's Avatar
FlamingClaw FlamingClaw is offline Offline
Posting Pro in Training

Re: Could you tell me what is wrong of my answer?

 
0
  #2
Apr 4th, 2009
Here is the fixed version of your program
  1.  
  2. (*
  3. Dear Sir / Madam,
  4.  
  5. The following is the game of Rock, Paper, Scissors.
  6. But I don't know why computer is always choose Rock.
  7.  
  8. My Answer:-
  9.  *)
  10. Program RPS5;
  11.  
  12. {$APPTYPE CONSOLE}
  13.  
  14. Uses
  15. SysUtils;
  16. var Computer : integer;
  17. Choice, Move : char;
  18. Begin //main
  19. Repeat
  20. WriteLn('Rock(R), Paper(P), Scissors(S)');
  21. ReadLn(Choice);
  22. Until (Choice = 'R') Or (Choice = 'P') Or (Choice = 'S');
  23. Case Choice Of
  24. 'R': WriteLn('You have chosen Rock');
  25. 'P': WriteLn('You have chosen Paper');
  26. 'S': WriteLn('You have chosen Scissors');
  27. End;//case
  28. Randomize; (* <-- you forget about randomize,not? *)
  29. Computer:= Random(2);
  30. Case Computer of
  31. 0: Begin
  32. WriteLn('Computer have chosen Rock');
  33. Move:='R';
  34. If (Move=choice) Then Begin
  35. Writeln('Draw')
  36. End //'if' move
  37. Else Begin
  38. If Choice='S' Then Begin
  39. WriteLn ('You lose')
  40. End //'if' choice
  41. Else WriteLn('You win');
  42. End;//else
  43. End;//case 0
  44. 1: Begin
  45. WriteLn('Computer have chosen Paper');
  46. Move:='P';
  47. If (Choice=Move) Then Begin
  48. Writeln('Draw');
  49. End
  50. Else Begin
  51. If (Choice='R') Then Begin
  52. Writeln ('You lose');
  53. End
  54. Else writeln('You win');
  55. End;
  56. End;//case 1
  57. 2: Begin
  58. WriteLn('Computer have chosen Scissors');
  59. Move:='S';
  60. If (Choice=Move) Then Begin
  61. Writeln('Draw');
  62. End
  63. Else Begin
  64. If (Choice='P') Then Begin
  65. Writeln ('You lose');
  66. End
  67. Else writeln('You win');
  68. End;
  69. End;//case 2
  70. End;//case main
  71.  
  72. //sleep(10000);
  73. ReadLn; //I put this line,waiting for press the enter button
  74. End.//of main program
  75.  
  76. (*
  77. -=Note By FlamingClaw=-
  78. I dont know your 'ourcrt',so I put it out
  79. Sorry for formatting your program,but now already readable...to me.
  80. You forget about randomize!!!
  81. -=Created By FlamingClaw=-
  82. -=2009.04.04=-
  83. *)
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...
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC