Could you express the meaning of the 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 express the meaning of the answer?

 
0
  #1
Jul 7th, 2009
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:

Pascal and Delphi Syntax (Toggle Plain Text)
  1.  
  2. program RPS5;
  3.  
  4. {$APPTYPE CONSOLE}
  5.  
  6. uses
  7. SysUtils,
  8. ourcrt;
  9.  
  10. var
  11. Computer : integer;
  12. Choice, Move : char;
  13.  
  14. begin
  15.  
  16. randomize;
  17. repeat
  18. writeln('Rock(R), Paper(P), Scissors(S)');
  19. readln(Choice);
  20. until (Choice = 'R') or (Choice = 'P') or (Choice = 'S');
  21.  
  22. case Choice of
  23. 'R': writeln('You have chosen Rock');
  24. 'P': writeln('You have chosen Paper');
  25. 'S': writeln('You have chosen Scissors');
  26. end;
  27.  
  28. Computer:= random (2);
  29.  
  30. case Computer of
  31. 0: begin writeln('Computer have chosen Rock');
  32. Move:='R';
  33. if Move=choice then begin Writeln('Draw') end
  34. else
  35. if Choice='S' then begin Writeln ('You lose') end
  36. else writeln('You win') end;
  37.  
  38. 1: begin writeln('Computer have chosen Paper');
  39. Move:='P';
  40. if Choice=Move then begin Writeln('Draw') end
  41. else
  42. if Choice='R' then begin Writeln ('You lose') end
  43. else writeln('You win') end;
  44.  
  45. 2: begin writeln('Computer have chosen Scissors');
  46. Move:='S';
  47. if Choice=Move then begin Writeln('Draw') end
  48. else
  49. if Choice='P' then begin Writeln ('You lose') end
  50. else writeln('You win') end;
  51. end;
  52.  
  53. readln;
  54. 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,
Last edited by turbomen; Jul 7th, 2009 at 1:13 am. Reason: I have wrong input the information.
Reply With Quote Quick reply to this message  
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

Re: Could you express the meaning of the answer?

 
0
  #2
Jul 7th, 2009
And could you tell me why '0: begin writeln('Computer have chosen Rock')' as well??

Cheers,

Tony
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 443
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 express the meaning of the answer?

 
0
  #3
Jul 7th, 2009
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...
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
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  
Join Date: Feb 2009
Posts: 443
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 express the meaning of the answer?

 
0
  #4
Jul 7th, 2009
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 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:



Similar Threads
Other Threads in the Pascal and Delphi Forum
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC