| | |
Could you express the meaning of the answer?
Thread Solved |
•
•
Join Date: Feb 2009
Posts: 93
Reputation:
Solved Threads: 0
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:
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,
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)
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,
Last edited by turbomen; Jul 7th, 2009 at 1:13 am. Reason: I have wrong input the information.
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
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...
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...
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;
....
....
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...
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
- Could you express the meaning of this again... (Pascal and Delphi)
- Could you express the meaning of this ... (Pascal and Delphi)
- Please express the meaning of it. (Pascal and Delphi)
- Advantages of vb.net (VB.NET)
- outlook express problems (Web Browsers)
- What is a Geek? (Geeks' Lounge)
- Outlook Express freezes up - CPU usage at 99% (Windows Software)
Other Threads in the Pascal and Delphi Forum
- Previous Thread: how to use RegexBuddy? can you help me.
- Next Thread: Pointers - question
| Thread Tools | Search this Thread |





