PDA

View Full Version : Pascal code help.


Rob.K
03-13-2005, 08:35 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}

JamieR
03-13-2005, 10:27 PM
Hey, could you put that in the brackets please? it would make it easier to read.

Jamie.

Rob.K
03-14-2005, 12:10 AM
EDIT:
If you know how to edit it so it runs please take a stab at it, I've been told it shouldnt be to hard but im useless at this. I dont know whether I need to set variables or anything.
PS: this is not part of a code it is the FULL code.
took out the doublet // David

liorean
03-14-2005, 12:20 AM
Oh, weazel just meant that you should have wrapped it in a [code] block to preserve indentation.

Rob.K
03-14-2005, 12:32 AM
Edited my post :).

liorean
03-14-2005, 12:36 AM
Oh, there was no need for that. I already edited it into your original post.

Rob.K
03-14-2005, 12:45 AM
Wo, you mods here are on form! Good job guys.
Don't s'pose either of you have any idea about my code do you?

liorean
03-14-2005, 01:11 AM
Sorry, but I haven't used Pascal for the last eleven, maybe twelve years. You'll have to wait for someone who has a bit more recent experience with it to come by.