Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

We want you to make a Craps simulator. You are required to have at least one use

ID: 3639845 • Letter: W

Question

We want you to make a Craps simulator.
You are required to have at least one user defined function in the code (Perhaps for example a int rollDice() function).

Roll Two 6 sided dice.
* 7 or 11 on the first roll -> player wins.
* 2, 3, or 12 on the first roll -> player loses
* 4,5,6,8,9,10 -> the value becomes the player's 'point'. The player must roll that value before they roll a 7 in order to win.

#(Output example)

./Craps
Players rolls 6+5=11
Player wins

./Craps
Player rolls 6+6=12
Player loses

./Craps
Player rolls 4+6=10
Point is 10
Player rolls 4+2=6
Player rolls 5+6=11
Player rolls 3+3=6
Player rolls 5+5=10
Player wins

./
Player rolls 2+2=4
Point is 4
Player rolls 4+1=5
Player rolls 6+3=9
Player rolls 4+6=10
Player rolls 5+4=9
Player rolls 1+2=3
Player rolls 6+1=7
Player loses

Explanation / Answer

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

int diceRoll(void)
{
return (rand()%6)+1;
}

int main ( void )
{
int done = 0, roll1, roll2, point, rolled;

srand(time(0));
point = -1;

while (!done)
{
roll1 = diceRoll();
roll2 = diceRoll();

printf ("Player rolls %d + %d = %d ", roll1, roll2, roll1+roll2);
rolled = roll1 + roll2;

if (point == -1) // must be first roll
{
switch (rolled)
      {
        case 7: case 11:
          printf ("Player wins. ");
          done = 1;
          break;

        case 2: case 3: case 12:
          printf("Player loses ");
          done = 1;
          break;

      default:
          point = rolled;
          printf("Point is %d ", point);
          break;
      }
}
else
{
      if (rolled == 7)
      {
        printf("Player Loses! ");
        done = 1;
      }
      else if (rolled == point)
      {
        printf ("Player wins. ");
        done = 1;
      }
}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote