Debugging Craps Simulating Game: Tracking Wins & Losses

In summary, the player can win if the point is rolled or if the point is rolled first and the player rolls a 7.
  • #1
brad sue
281
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
  • #2
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:
  • #3


Hi Bertrand,

Thank you for sharing your code and explaining your problem. It looks like you are on the right track with your code, but there are a few things that can be improved to make it more organized and efficient.

First, I would suggest creating a variable to track the total number of wins and losses. You can initialize it to 0 before the game starts and then update it accordingly as the game progresses.

Next, I would suggest using a switch statement instead of multiple if statements to handle the different possible outcomes of the game. This will make your code more organized and easier to read.

Here is an example of how you can modify your code using a switch statement:

int wins = 0; // variable to track wins
int losses = 0; // variable to track losses

// code for the come out roll
int roll = dice(); // simulate the roll of two dice

switch(roll) {
case 7:
case 11:
// player wins
cout << "Player wins!" << endl;
wins++;
break;
case 2:
case 3:
case 12:
// player loses
cout << "Player loses" << endl;
losses++;
break;
default:
// point case
cout << "Point is set to " << roll << endl;
do {
roll = dice(); // simulate the roll of two dice
cout << "Roll " << roll << endl;
if (roll == 7) {
// player loses
cout << "Player loses" << endl;
losses++;
break;
} else if (roll == point) {
// player wins
cout << "Player wins!" << endl;
wins++;
break;
}
} while (true);
break;
}

// after the game is over, you can print the total number of wins and losses
cout << "Total wins: " << wins << endl;
cout << "Total losses: " << losses << endl;

I hope this helps and good luck with your coding!
 

1. What is the purpose of debugging a craps simulating game?

The purpose of debugging a craps simulating game is to identify and fix any errors or bugs in the code that may be causing incorrect outcomes or crashes. This ensures that the game runs smoothly and accurately simulates a real game of craps.

2. How do you track wins and losses in a craps simulating game?

Wins and losses can be tracked by keeping a running total of the player's balance, which is updated after each round of the game. A win or loss can be determined by comparing the player's final balance to their initial balance. Alternatively, a separate variable can be used to track the number of wins and losses separately.

3. Can you explain the concept of a "point" in craps?

In craps, a "point" is a number that is established on the first roll of the game. This can be a 4, 5, 6, 8, 9, or 10. If the player rolls this number again before rolling a 7, they win. However, if a 7 is rolled before the point, the player loses. This adds an extra layer of complexity to the game and increases the potential for wins and losses.

4. What are some common errors that may occur in a craps simulating game?

Some common errors that may occur in a craps simulating game include incorrect calculations of probabilities, incorrect handling of the "point" concept, and incorrect handling of various types of bets. It is important to thoroughly test the game and identify and fix any errors before releasing it for use.

5. How can debugging a craps simulating game benefit players?

Debugging a craps simulating game can benefit players by ensuring that the game follows the rules and odds of a real game of craps. This creates a fair and accurate simulation, allowing players to practice and improve their skills before playing in a real casino setting. Additionally, debugging can also help identify any potential biases or glitches in the game, making it a more enjoyable and reliable experience for players.

Similar threads

  • Programming and Computer Science
Replies
1
Views
4K
  • Programming and Computer Science
Replies
1
Views
3K
  • Programming and Computer Science
Replies
1
Views
3K
  • Precalculus Mathematics Homework Help
Replies
11
Views
2K
  • Precalculus Mathematics Homework Help
2
Replies
53
Views
5K
  • Programming and Computer Science
Replies
5
Views
2K
  • General Math
Replies
2
Views
7K
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
33
Views
6K
  • Set Theory, Logic, Probability, Statistics
Replies
1
Views
1K
Back
Top