The game of craps is often said to be the fairest casino gam

The game of craps is often said to be the “fairest” casino game of pure chance (meaning that there is no player strategy involved) in that the house has the smallest advantage over the player. What is that advantage? To answer this question we need to first define, precisely, what we mean by “advantage”. The house advantage is simply the fraction of bets placed that will go to the house, on average.
To estimate the house advantage for craps perform a Monte Carlo simulation of the game for many millions of games, keeping track of the total amount bet and the total amount collected by the house.
The rules of craps are very simple (note that we are not considering “side bets”). A player places a wager and they will either lose the game (and their wager) or they will win the game (and get both their wager and an equal payout from the house). Each game consists of a number of throws of two fair six-sided dice (with sides equal to {1,2,3,4,5,6}. On each roll the sum of the two dice is calculated. On the first roll, if a player rolls a 7 or an 11 they win immediately. If the first roll is 2, 3, or 12 they lose immediately. Any other result establishes the player’s “point” for that game. They then continue rolling the dice until they either roll their point again (and win) or roll a 7 (and lose).
Write a predicate function that plays a single game of craps and returns TRUE if the player wins and FALSE if the player loses. On each game place a random bet ranging from $1 to $1000 (whole dollar increments is fine). Collect data not only on the total amount wagered and the total (net) amount taken by the house, but also aggregate data on how long games last and their outcome. The end result should be output similar to the following (fake data). Note that the percentages in parens on each line are the percentage of games that lasted that length, not the fraction of total games played. The last column is the percentage of all games that lasted that number of rolls.

this is what i have so far got any suggestion

//======================================================================
// PROGRAMMER: ......... O\'CONNOR, Jordan D
// UCCS USER NAME: ..... Joconno4
// COURSE: ............. CS-2060
// TERM: ............... 2017 Spring
// ASSIGNMENT: ......... HW01
// DUE DATE: ........... 27 JAN 2017
// PROBLEM: ............ PR01
// FILENAME: ........... Problem 1.c
// VERSION: ............ 1.1
// IDE/COMPILER:........ Bloodshed/Orwell Dev-C++ Version 5.11
//======================================================================

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
   int longestRound = 0;
   int diceCount = 0;
   int games = 1000000;
   int end = 1;
   int win;
      
   int frequencyWin[20] = {0};
   int frequencyLose[20] = {0};
  
   int frequencyWin2[1] = {0};
   int frequencyLose2[1] = {0};
  
   for (int roll = 1; roll <= 6000000; ++roll)
   {
       int tryOne = (1 + rand() % 6) + (1 + rand() % 6);
      
       if (tryOne == 7)
       {
           win = 1;
           diceCount += 1;
          
       } else if (tryOne == 11)
       {
           win = 1;
           diceCount += 1;
          
       } else if (tryOne == 2)
       {
           win = 0;
           diceCount += 1;
          
       } else if (tryOne == 3)
       {
           win = 0;
           diceCount += 1;
          
       } else if (tryOne == 12)
       {
           win = 0;
           diceCount += 1;
          
       } else
       {
           while (end != 0)
           {
               int tryTwo = 1 + rand() % 6 + 1 + rand() % 6;
               if (tryTwo == tryOne)
               {
                   win = 1;
                   diceCount += 1;
                   end = 0;
               } else if (tryTwo == 7)
               {
                   win = 0;
                   diceCount += 1;
                   end = 0;
               } else
               {
                   diceCount += 1;
                   end = 1;
               }
           }
       }
       int sizeOfArrayWin = sizeof(frequencyWin);
       int sizeOfArrayLose = sizeof(frequencyLose);
      
       if (win == 1)
       {
           if (diceCount > sizeOfArrayWin)
           {
               frequencyWin2[diceCount + 1];
               for (int count = 1; count < sizeOfArrayWin; count++)
               {
                   frequencyWin2[count] = 0;
                   for (int count2 = 0; count2 < frequencyWin[count]; count2++)
                   {
                       ++frequencyWin2[count];
                   }
               }
              
               ++frequencyWin2[diceCount];
              
               frequencyWin[sizeof(frequencyWin2)];
              
               for (int count = 1; count < sizeof(frequencyWin2); count++)
               {
                   frequencyWin[count] = 0;
                  
                   for (int count2 = 0; count2 < frequencyWin2[count]; count2++)
                   {
                       ++frequencyWin[count];
                   }
               }
           } else
           {
               ++frequencyWin[diceCount];
           }
       }  
       else {
           if (diceCount > sizeOfArrayLose)
           {
               frequencyWin2[diceCount + 1];
               for (int count = 1; count < sizeOfArrayLose; count++)
               {
                   frequencyLose2[count] = 0;
                   for (int count2 = 0; count2 < frequencyLose[count]; count2++)
                   {
                       ++frequencyLose2[count];
                   }
               }
              
               ++frequencyLose2[diceCount];
              
               frequencyLose[sizeof(frequencyLose2)];
               for (int count = 1; count < sizeof(frequencyLose2); count++)
               {
                   frequencyLose[count] = 0;
                  
                   for (int count2 = 0; count2 < frequencyLose2[count]; count2++)
                   {
                       ++frequencyLose[count];
                   }
               }
           } else
           {
               ++frequencyLose[diceCount];
           }
       }
      
       if (diceCount >= longestRound)
       {
           longestRound = diceCount;
       }
          
       diceCount = 0;
   }
  
   for (int count = 1; count < sizeof(frequencyLose); count++)
   {
       printf(\"%4d%17d\ \", count, frequencyLose);
       printf(\"%4d%17d\ \", count, frequencyWin);
   }
}

Solution

#include<stdio.h>
#include <stdlib.h>

   //Enumeration with constants that represent the game status
   enum Status {CONTINUE, WON, LOST}gameStatus;
int count = 0;
int wagered = 0;
int amt = 0;
   //Play one game of Craps
   void play()
   {
       //Point if no win or loss on first roll
       int myPoint = 0;

       //Can contain CONTINUE, WON OR LOST
       //Status gameStatus;

       //First roll of the dice
       int sumOfDice = rollDice();

       //Determine game status and point based on first roll
       switch(sumOfDice)
       {
           //Win with 7 or 11 on first roll
           case 7:
           case 11:
               gameStatus = WON;
               amt += wagered;
               break;
           //lose with 2, 3, 12 on first roll
           case 2:
           case 3:
           case 12:
               gameStatus = LOST;
               amt = 0;
               break;
               //Did not win or loss, so remember point
           default:
               //Game is not over
               gameStatus = CONTINUE;
               //Remember the point
               myPoint = sumOfDice;
               //printf(\"Point is %d \", myPoint);
               break;
       }

       //While the game is not complete (not WON or LOST)
       while(gameStatus == CONTINUE)
       {
           sumOfDice = rollDice();

           //Determine the game status
           if(sumOfDice == myPoint)   //Win by making point
{
gameStatus = WON;
amt += wagered;
}

           //Loss by rolling 7 before point
           else if(sumOfDice == 7)
{
gameStatus = LOST;
amt -= wagered;
}
       }//End while

       //Display won or lost message
       if(gameStatus == WON)
{
printf(\"\ Player Wins. \ Amount taken home = %d\", amt);
}
       else
{
printf(\"\ Player Looses. \ Amount taken home = %d\", amt);
}

   }//End of method play

   //Roll dice, calculate sum and display result s
   int rollDice()
   {
       //Pick random die values
       int die1 = rand() % 6 + 1;
       int die2 = rand() % 6 + 1;
       int sum = die1 + die2;

count++;
       //Display results of this roll
       printf(\"\ Player rolled %d + %d = %d\", die1, die2, sum);
       printf(\"\ Wagered amount = %d\", wagered);

       return sum;
   }//End of method roll dice

   int main()
   {
   int x;
   for(x = 0; x < 3; x++)
{
wagered = rand() % 1000 + 1;
play();
}
//Number of times rolled
       printf(\"\ Number of times rolled = %d\", count );
   }//End of main

Output:

Player rolled 6 + 5 = 11
Wagered amount = 42
Player Wins.
Amount taken home = 42
Player rolled 6 + 5 = 11
Wagered amount = 501
Player Wins.
Amount taken home = 543
Player rolled 1 + 5 = 6
Wagered amount = 479
Player rolled 3 + 6 = 9
Wagered amount = 479
Player rolled 6 + 2 = 8
Wagered amount = 479
Player rolled 4 + 2 = 6
Wagered amount = 479
Player Wins.
Amount taken home = 1022
Number of times rolled = 6

The game of craps is often said to be the “fairest” casino game of pure chance (meaning that there is no player strategy involved) in that the house has the sma
The game of craps is often said to be the “fairest” casino game of pure chance (meaning that there is no player strategy involved) in that the house has the sma
The game of craps is often said to be the “fairest” casino game of pure chance (meaning that there is no player strategy involved) in that the house has the sma
The game of craps is often said to be the “fairest” casino game of pure chance (meaning that there is no player strategy involved) in that the house has the sma
The game of craps is often said to be the “fairest” casino game of pure chance (meaning that there is no player strategy involved) in that the house has the sma

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site