Dear ALL,

I have tried to demonstrate the card game problem by myself. The card game is come together with 52 cards. It has Spade, Heart, Club and Diamond - Spade > Heart > Club > Diamond. It has the integers and chars 2,3,4,5,6,7,8,9,10,J,Q,K,A. Could you tell me how can I code this program if we only play for 5 times. We choose 1 card in every time randomly.

Cheers,

turbomen

i had a little time to continue the card game....

``````program solution;

var lapok:array[1..12]of string[1];{the cards,2,3,4,5...J,Q,K,A}
kezd:byte;{who begins the game}
lapszam:byte;{the numbers of the card }
i,num:byte;
s:string[1];
you,computer,draw:byte;
lapyou,lapcomputer:array[1..4]of string[1];
temp:byte;

procedure stars;
var x:byte;
begin
writeln;
for x:=1 to 20 do write('*-');
writeln;
end;

begin
lapszam:=52;
you:=0;
computer:=0;
draw:=0;
randomize;
stars;
writeln('Welcome to my card game!');
writeln('There are 52 cards.');
write('The available cards are: ');
{fill up the array}
for i:=1 to 12 do begin
case (i) of
9:lapok[i]:='J';
10:lapok[i]:='Q';
11:lapok[i]:='K';
12:lapok[i]:='A';
else begin
num:=i+1;
str(num,s); {converts number to string,built in procedure}
lapok[i]:=s;
end;
end;{of case}
write(lapok[i],' ');
end;{of for}
stars;
{now the program adds to you four cards}
for i:=1 to 4 do begin
temp:=random(12)+1;
lapyou[i]:=lapok[temp];
write(lapyou[i],' ');
end;
writeln;
write('Computer cards are : ');
for i:=1 to 4 do begin
temp:=random(12)+1;
lapcomputer[i]:=lapok[temp];
write(lapcomputer[i],' ');
end;
stars;
for i:=1 to 5 do begin
{let's see,who begins the game...}
kezd:=random(2);
temp:=random(5);
writeln(i,'. round.');
if temp = 0 then temp:=1;
if kezd=0 then begin
writeln('You begins the game!');

write('you: ',lapyou[temp],'  ');
writeln('computer: ',lapcomputer[temp]);
if lapyou[temp]>lapcomputer[temp] then
begin
you:=you+1;
writeln('you win.');
end;
if lapyou[temp]<lapcomputer[temp] then
begin
computer:=computer+1;
writeln('computer win.');
end;
if lapyou[temp]=lapcomputer[temp] then
begin
draw:=draw+1;
writeln('draw.');
end;
end
else begin
writeln('Coputer begins the game!');

write('computer: ',lapcomputer[temp],' ');
writeln('you: ',lapyou[temp]);
if lapyou[temp]>lapcomputer[temp] then
begin
you:=you+1;
writeln('you win.');
end;
if lapyou[temp]<lapcomputer[temp] then
begin
computer:=computer+1;
writeln('computer win.');
end;
if lapyou[temp]=lapcomputer[temp] then
begin
draw:=draw+1;
writeln('draw.');
end;
end;
end;{of for}
stars;
write('YOU: ',you,'   COMPUTER: ',computer,'   DRAW: ',draw);