Pascal Code.

help required.

Page 1 of 1

3 Replies - 2729 Views - Last Post: 12 April 2005 - 05:21 PM Rate Topic: -----

#1 Sarah.K  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 13-March 05

Pascal Code.

Posted 13 March 2005 - 07:03 PM

Hi,
I have the following code and just wondered if anyone could tell me why it doesnt compile and what edits I need to do to make it work.
It's basically a card game which follows these rules:

1) Imagine computer randomly selects a card from a pack of cards.
2) The first player must guess the suit then its value
3) After each guess for the suit a message will display whether the
player was correct or not.
4) After each guess for the value a message will display whether the
player was correct, too high or too low.

Here is the code:
procedure game;
var suitguess,valueguess : string;
    valueguessint, suitguessint,valid : integer;
    validbool : boolean;

begin
     generateno;
     guesses := 0;

     repeat
           suitcorrect := false;
           valuecorrect := false;
           repeat
                 Writeln('Enter Suit Guess');
                 writeln;
                 writeln('1 : Club');
                 writeln('2 : Spade');
                 writeln('3 : Heart');
                 writeln('4 : Diamond');
                 writeln;
                 writeln;
                 Readln(suitguess);

                 val(suitguess, suitguessint, valid);
                 validbool := true;
                 if (suitguessint <1) or (suitguessint >4) or (valid <> 0) then
                    begin
                         validbool := false;

                         writeln('Please enter a number from 1 to 4');

                         writeln('Press any key to try again');
                         readkey;
                    end;
           until validbool = true;

If suitguessint = suitno then
        begin
             writeln('Correct');
             suitcorrect := true;
        end
     else
         writeln('Incorrect');
readkey;


begin
     repeat
           Writeln('Enter Value Guess');
           writeln('1  = ace');
           writeln('11 = jack');
           writeln('12 = queen');
           writeln('13 = king');
           writeln('all other numbers are represented by thier number value');
           writeln;
           readln(valueguess);
           val(valueguess, valueguessint, valid);
           validbool := true;
                 if (valueguessint <1) or (valueguessint >13) or (valid <> 0) then
                    begin
                         validbool := false;

                         writeln('Please enter a number from 1 to 13');

                         writeln('Press any key to try again');
                         readkey;
                    end;
     until validbool = true;

     If valueguessint = value then

     begin
          writeln('Correct');
          valuecorrect := true
     end

        else
         begin
         writeln('Incorrect');

              If value < valueguessint then
                 writeln(' The value is less than ',valueguess)
              else
                 writeln(' The value is greater than ',valueguess);
         end;
         readkey;
         end;
 guesses := guesses +1;

until (suitcorrect AND valuecorrect) = true;

writeln('Game complete');
writeln('press any key to continue to next game');
totalguesses[activeplayer(gameno)] := totalguesses[activeplayer(gameno)] + guesses;
readkey;
end; {proc}


The code was part of a bigger code and has been edited a bit. Now I believe I just need to put a start, end and add the variables etc to make it run as a single game. If anyone fancies taking a stab at it I would be most grateful.
Ideally im trying to get the code into an executable form so the game plays as described.

Thanks.

This post has been edited by Sarah.K: 13 March 2005 - 07:06 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Pascal Code.

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Pascal Code.

Posted 13 March 2005 - 07:53 PM

What errors are you getting on compilation? It may help to narrow down the problem...although not likely for me. I haven't touched pascal in forever.
Was This Post Helpful? 0
  • +
  • -

#3 born2c0de  Icon User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 180
  • View blog
  • Posts: 4,667
  • Joined: 26-November 04

Re: Pascal Code.

Posted 13 March 2005 - 09:59 PM

I've programmed quite a lot with pascal but i just dont use it anymore...meaning I dont have a pascal compiler. What compile errors are you getting? Once I get those I can help you out...( because at first glance, your code seems clean enough )
Was This Post Helpful? 0
  • +
  • -

#4 SusiTohir  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 07-April 05

Re: Pascal Code.

Posted 12 April 2005 - 05:21 PM

I think you should declare many variables on your code such suitno, gameno...etc. You can check again.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1