Debugging Craps Simulating Game: Tracking Wins & Losses

AI Thread Summary
The discussion focuses on debugging a craps simulation game, specifically the logic for tracking wins and losses after the "come out roll." The code provided outlines how to handle the scenario when a point is established, with conditions for winning or losing based on subsequent rolls of the dice. Key issues include ensuring the correct tracking of wins and losses, as well as properly structuring the loop to continue rolling until a win or loss condition is met. Participants are asked to help organize and refine the code to improve its functionality. The main goal is to accurately simulate the game mechanics and count the outcomes effectively.
brad sue
Messages
270
Reaction score
0
Hi ,
I have a problem coding a part of a simulating game:

In the game of craps, a "Pass line" bet proceeds as follows. The first roll of the two, six-sided dice in a craps round is called the "come out roll". The bet immediately wins when the come out roll is 7 or 11, and loses when the come out is 2,3 or 12.
If 4,5,6,8,9 or 10 is rolled on the come out roll, that number becomes " the point". The player keeps rolling the dice until either 7 or the point is rolled. If the point is rolled first, then the player wins the bet. If the player rolls a 7 first, the the player loses.
you need to indicate the total number of wins and losses.


The part that bothers me is the underline part.
This is the code I've done for this underlined part:

Code:
.
.
.
if(roll==4||roll==5||roll==6||roll==8||roll==9||roll==10)//point case
        { 
          cout<<roll<<" points"<<endl;
        do
         {
          roll=dice();//dice- function that simulates the 2 dice throwings
          cout<<endl;
          cout<<"roll "<<roll<<endl;
          if(roll==7)
          cout<<roll<<" the point got to 7. player loses"<<endl;
          if(roll==4||roll==5||roll==6||roll==8||roll==9||roll==10)
          cout<< roll<<" the roll got to 'point'. player wins"<<endl;
         }
          while(roll==7||roll==4||roll==5||roll==6||roll==8||roll==9||roll==10);
       }// end if
.
.
.

Please can you help to organize my code ?
Thank you
Bertrand
 
Technology news on Phys.org
int timesToPlay = 100;
int gamesPlayed = 0;
int wins = 0;
int losses = 0;
.

.

.

if(roll==4||roll==5||roll==6||roll==8||roll==9||roll==10)//point case
{
int flag = 0;
cout<<"The point is "<<roll<<endl;
point = roll;
do
{
roll=dice();//dice- function that simulates the 2 dice throwings
cout<<endl;
cout<<"roll = "<<roll<<endl;
if(roll==7) {
cout<<roll<<" was rolled. Player loses."<<endl; losses++; flag = 1; }
if(roll==point) {cout<< roll<<" was rolled. Player got the 'point'. player wins"<<endl; wins++; flag = 1;}
} while (flag == 0)
}// end if

.
.
.

This seems to be what you were trying to say.
 
Last edited:
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top