![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Apr 2005
Posts: 4
Rep Power: 0
![]() |
Craps in Pascal
I need some help with this program. I am a beginning pascal programmer and I am a bit lost in this program for the game craps.
program ch52;
uses wincrt;
var die1,die2 : real;
var x,a,b,p,a2,b2 : integer;
var die1a,die2a : string;
procedure header;
begin
writeln('The game of Craps');
writeln('How to play:');
writeln('Roll the dice. If the sum of the dice is 7 or 11 then the player wins.');
writeln('If the roll is not a 7 or 11 then the player continues to roll until ');
writeln('they roll a number equal to their first roll. If the player rolls a ');
writeln('7 or 11 on any other roll except for the first. You lose. Get it, good.');
writeln('So when you are ready. Hit enter to begin.');
end;
procedure craps;
begin
randomize;
die1:=random(6) + 1;
randomize;
die2:=random(6) + 1;
if die1=1 then
begin
die1a:='1';
end
else if die1=2 then
begin
die1a:='2';
end
else if die1=3 then
begin
die1a:='3';
end
else if die1=4 then
begin
die1a:='4';
end
else if die1=5 then
begin
die1a:='5';
end
else if die1=6 then
begin
die1a:='6';
end
else if die2=1 then
begin
die2a:='1';
end
else if die2=2 then
begin
die2a:='2';
end
else if die2=3 then
begin
die2a:='3';
end
else if die2=4 then
begin
die2a:='4';
end
else if die2=5 then
begin
die2a:='4';
end
else if die2=5 then
begin
die2a:='5';
end
else if die2=6 then
begin
die2a:='6';
end
else if (die1a='1') and (die2a='1') then
begin
writeln('Snake eyes!');
x := x + 1;
end
else if (die1a='8') and (die2a='8') then
begin
writeln('Box Cars!');
x := x + 1;
end
else if (die1a='1') and (die2a='6')
or (die1a='2') and (die2a='5')
or (die1a='3') and (die2a='4')
or (die1a='6') and (die2a='1')
or (die1a='5') and (die2a='2')
or (die1a='4') and (die2a='3')
or (die1a='6') and (die2a='5')
or (die1a='5') and (die2a='6')
and (x <= 1) then
begin
writeln('You win!');
end
else if (die1a='1') and (die2a='6')
or (die1a='2') and (die2a='5')
or (die1a='3') and (die2a='4')
or (die1a='6') and (die2a='1')
or (die1a='5') and (die2a='2')
or (die1a='4') and (die2a='3')
or (die1a='6') and (die2a='5')
or (die1a='5') and (die2a='6')
and (x >= 2) then
begin
writeln('You Lose!');
end;
if(die1a<>'1') or (die1a<>'8')
and (die2a<>'1') or (die2a<>'8')
and (x > 1) then
begin
writeln('Roll again.');
x := x + 1;
end;
end;
procedure output;
begin
write(die1a:1);
write(die2a:1);
readln;
repeat
writeln(die1a:1);
writeln(die2a:1);
readln;
until (x = 9);
end;
begin
x := 1;
header;
readln;
clrscr;
craps;
output;
readln;
donewincrt;
end.this is going to make me cry. |
|
|
|
|
|
#2 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Learn how to tab, and I'll take a look.
|
|
|
|
|
|
#3 |
|
Newbie
Join Date: Apr 2005
Posts: 4
Rep Power: 0
![]() |
Actually it was formatted but it read the FAQ and it said somehting about removing spaces. So I thought I was just follow the forum rules.
|
|
|
|
|
|
#4 |
|
Newbie
Join Date: Apr 2005
Posts: 4
Rep Power: 0
![]() |
here.
program ch52;
uses wincrt;
var die1,die2 : real;
var x,a,b,p,a2,b2 : integer;
var die1a,die2a : string;
procedure header;
begin
writeln('The game of Craps');
writeln('How to play:');
writeln('Roll the dice. If the sum of the dice is 7 or 11 then the player wins.');
writeln('If the roll is not a 7 or 11 then the player continues to roll until ');
writeln('they roll a number equal to their first roll. If the player rolls a ');
writeln('7 or 11 on any other roll except for the first. You lose. Get it, good.');
writeln('So when you are ready. Hit enter to begin.');
end;
procedure craps;
begin
randomize;
die1:=random(6) + 1;
randomize;
die2:=random(6) + 1;
if die1=1 then
begin
die1a:='1';
end
else if die1=2 then
begin
die1a:='2';
end
else if die1=3 then
begin
die1a:='3';
end
else if die1=4 then
begin
die1a:='4';
end
else if die1=5 then
begin
die1a:='5';
end
else if die1=6 then
begin
die1a:='6';
end
else if die2=1 then
begin
die2a:='1';
end
else if die2=2 then
begin
die2a:='2';
end
else if die2=3 then
begin
die2a:='3';
end
else if die2=4 then
begin
die2a:='4';
end
else if die2=5 then
begin
die2a:='4';
end
else if die2=5 then
begin
die2a:='5';
end
else if die2=6 then
begin
die2a:='6';
end
else if (die1a='1') and (die2a='1') then
begin
writeln('Snake eyes!');
x := x + 1;
end
else if (die1a='8') and (die2a='8') then
begin
writeln('Box Cars!');
x := x + 1;
end
else if (die1a='1') and (die2a='6')
or (die1a='2') and (die2a='5')
or (die1a='3') and (die2a='4')
or (die1a='6') and (die2a='1')
or (die1a='5') and (die2a='2')
or (die1a='4') and (die2a='3')
or (die1a='6') and (die2a='5')
or (die1a='5') and (die2a='6')
and (x <= 1) then
begin
writeln('You win!');
end
else if (die1a='1') and (die2a='6')
or (die1a='2') and (die2a='5')
or (die1a='3') and (die2a='4')
or (die1a='6') and (die2a='1')
or (die1a='5') and (die2a='2')
or (die1a='4') and (die2a='3')
or (die1a='6') and (die2a='5')
or (die1a='5') and (die2a='6')
and (x >= 2) then
begin
writeln('You Lose!');
end;
if (die1a<>'1') or (die1a<>'8')
and (die2a<>'1') or (die2a<>'8')
and (x > 1) then
begin
writeln('Roll again.');
x := x + 1;
end;
end;
procedure output;
begin
write(die1a:1);
write(die2a:1);
readln;
repeat
writeln(die1a:1);
writeln(die2a:1);
readln;
until ();
end;
begin
x := 1;
header;
readln;
clrscr;
craps;
output;
readln;
donewincrt;
end.I got lost with the procedure output. Because I am not sure how I would write the program where if the first roll isn't 7 or 11 then you keep rolling until you reach your first roll number again. But if you get 7 or 11 while rolling for the number you got the first time then you lose. So I am kind of lost. If you could give me some help with my coding I would appreciate it. And remember I am new at this, so I may have done stuff that seems very stupid. |
|
|
|
|
|
#5 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Simple:
repeat
craps;
output;
until finished; |
|
|
|
|
|
#6 |
|
Newbie
Join Date: Apr 2005
Posts: 4
Rep Power: 0
![]() |
ok. For the output, what would be my readlns and until? Because if try something like this
writeln(die1a:1);
readln(a);
writeln(die2a:1);
readln(b);
repeat
writeln(die1a:1);
readln(a2);
writeln(die2a:1);
readln(b2);
until (a2 = a) or (a2 = b) and (b2 = a) or (b2 = b) and (x >=2);But at the same time. Other numbers can also run equal to what you rolled the first time. For example I rolled a 3 and a 2 to get five but I rolled a 1 and 2 the next time. It needs to say they won. But the more I think about it the more I get lost. And this seems the be the only program out of the whole set that confuses me. I did a slot machine eariler and it works just fine. And in some ways this is equal to that. or so it seems to me. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|