Please, please help me with this code. 
Author Message
 Please, please help me with this code.

Please help me with this!  This code compiles, but it only displays 19
of the numbers.  It should disply all 52 do the screen.  I have to
crtl-break to get out of the program.  When I get back to the code,
the break is at the line <a := Random(52);> in the GetCards
procedure.  Any suggestions?  TIA.

{$R+}       { make sure range checking is ON }
program Prog5;

uses
  crt;

type

Digits = 0..51;
PlayingCards = set of Digits;

var
Deck : PlayingCards;
Card : Digits;
Response : char;

procedure WelcomeMessage;
begin
writeln('Welcome to Bridge.  Please press ''y'' to play or ''n'' to
quit.');
readln(Response);
end;

Procedure GetCards (var a: Digits; b: PlayingCards);
begin

repeat
  repeat
    Randomize;
    a := Random(52);
  until (a in b);
  write(a, '     ');
  b := b - [a];
until b = [ ];
end;

begin { main program }

  WelcomeMessage;
    while (UpCase (Response) = 'Y') do
      GetCards(Card, Deck);
end.

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Wed, 18 Jun 1902 08:00:00 GMT  
 Please, please help me with this code.

Quote:

>Please help me with this!  This code compiles, but it only displays 19
>of the numbers.  It should disply all 52 do the screen.  I have to
>crtl-break to get out of the program.  When I get back to the code,
>the break is at the line <a := Random(52);> in the GetCards
>procedure.  Any suggestions?  TIA.

You do not initialize the deck. You really should use a better method
for selecting cards. You could use an array that has values 0..51. Then
pick a random element and "take it out", put the last element in place
and decrement the count of elements.

Like;

ind:=random(cards_left);
a:=arr[ind];
arr[ind]:=arr[cards_left-1];
dec(cards_left);

and to initialize:

for ind:=0 to 51 do arr[ind]:=ind;
cards_left:=52;

That way the selection takes constant time.

Osmo



Wed, 18 Jun 1902 08:00:00 GMT  
 Please, please help me with this code.
The problem may also be that you go off the right end of the screen.  Your
write statement appears to write a number and then multiple (3?) blanks.
To display all of the numbers from 1 to 52 would take on the order of 200
characters, which is hard to fit on an 80-character screen.

Bob Schor
Pascal Enthusiast

Quote:

> Please help me with this!  This code compiles, but it only displays 19
> of the numbers.  It should disply all 52 do the screen.  I have to
> crtl-break to get out of the program.  When I get back to the code,
> the break is at the line <a := Random(52);> in the GetCards
> procedure.  Any suggestions?  TIA.

> {$R+}       { make sure range checking is ON }
> program Prog5;

> uses
>   crt;

> type

> Digits = 0..51;
> PlayingCards = set of Digits;

> var
> Deck : PlayingCards;
> Card : Digits;
> Response : char;

> procedure WelcomeMessage;
> begin
> writeln('Welcome to Bridge.  Please press ''y'' to play or ''n'' to
> quit.');
> readln(Response);
> end;

> Procedure GetCards (var a: Digits; b: PlayingCards);
> begin

> repeat
>   repeat
>     Randomize;
>     a := Random(52);
>   until (a in b);
>   write(a, '     ');
>   b := b - [a];
> until b = [ ];
> end;

> begin { main program }

>   WelcomeMessage;
>     while (UpCase (Response) = 'Y') do
>       GetCards(Card, Deck);
> end.

> Sent via Deja.com http://www.deja.com/
> Before you buy.



Wed, 18 Jun 1902 08:00:00 GMT  
 Please, please help me with this code.

|Please help me with this!
{.....}
|Procedure GetCards (var a: Digits; b: PlayingCards);
|begin

|repeat
|  repeat
|    Randomize;

Randomize should be called ONLY ONCE in the program.

|    a := Random(52);
|  until (a in b);
|  write(a, '     ');
|  b := b - [a];
|until b = [ ];
|end;

This may not be your primary problem, but when you get the rest
working, this would cause a serious problem.

Phil



Wed, 18 Jun 1902 08:00:00 GMT  
 Please, please help me with this code.


Quote:

>Procedure GetCards (var a: Digits; b: PlayingCards);
>begin

>repeat
>  repeat
>    Randomize;
>    a := Random(52);
>  until (a in b);
>  write(a, '     ');
>  b := b - [a];
>until b = [ ];
>end;

When starting a news-thread, please give an informative subject line,
describing the question; yours is useless.

Randomize should be called only once per program, under all normal
circumstances.  The on-line help clearly describes randomize as an
*initialiser*, and shows it as such in the example.

Otherwise, your method looks straightforward, should work (it is good to
see use of a set type) if "Deck" is initially filled, but is
inefficient, since near the end it spends most of its time looking for
an available card.

See my response to Clif Penn, posted today, in "Random Procedures?".

Please be aware that yours is in essence a common problem, and the
answers to common problems are to be found in TSFAQP.  Students could
save a considerable amount of time, much of this their own, by carefully
consulting TSFAQP **FIRST**.

--

 <URL: http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
 <URL: ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ;
 <URL: http://www.merlyn.demon.co.uk/clpb-faq.txt> Pedt Scragg: c.l.p.b. mFAQ.



Wed, 18 Jun 1902 08:00:00 GMT  
 Please, please help me with this code.

Quote:

> Procedure GetCards (var a: Digits; b: PlayingCards);
> begin

> repeat
>   repeat
>     Randomize;
>     a := Random(52);
>   until (a in b);
>   write(a, '     ');
>   b := b - [a];
> until b = [ ];
> end;

to improve it, and don't waste too much time a waiting he found a "A in
B", you should make
begin
  randomize;
  repeat
    a:=random(52)
    repeat
        if a<51 then inc(a) else a:=0;
    until (a in b);
    {same stuff then}
end;

i'm not sure what happen when you got inc(a) and a=52, so i uses the "if
badabada...". It may work with just inc(a) or succ(a), idonot know.
Maybe the prof could tell me if its stasticaly behave like a true deck
(sure not if you got to pass trhough the if a=51 then a:=0).



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. I need help fixing this CASE Select code, please help

2. please,please,please H E L P (tic tac toe)

3. Please, please, please H E L P (tic tac toe)

4. Program Idea Please please please

5. Program Idea Please Please Please

6. Graph.tpu for pascal wanted please, please, please.

7. Graph.tpu file wanted please, please, please.

8. PLEASE,PLEASE,PLEASE,WILL SOMEONE HELP ME WITH THIS CODE!!!!!!!!!!!!!!!

9. Please Please, help me with memo-fields, real problem

10. please, I beg of you help me please.

11. PLEASE PLEASE HELP ME

12. Please Please help me

 

 
Powered by phpBB® Forum Software