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

A player rolls two dice. Each die has 6 faces. These faces contain 1, 2, 3, 4, 5

ID: 3568118 • Letter: A

Question

A player rolls two dice. Each die has 6 faces. These faces contain 1, 2, 3, 4, 5, and 6 spots. After the dice have come to rest, the sum of the spots on the two upward faces are calculated. If the sum is 7 or 11 on the first roll, the player wins. If the sum is 2, 3, or 12 on the first roll, the player loses. If the sum is 4, 5, 6, 8, 9 or 10 on the first roll, the sum becomes the players "point". To win, you must continue rolling the dice until you "make your point" The player loses by rolling a 7 before making the point. Try playing this game. Start off with $1000.00 and each time you win you get back twice your bet. If you lose, you lose the amount you bet. See if you can set this up so that the program asks you if you want to stop playing. At the end print out if you are a winner or a loser.

Explanation / Answer

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

int main (void)

{
int i; int roll; int roll2; int points; int win1=0; int lose1=0; int win2=0; int lose2=0;
  
/*win1 is number of wins on first roll, win2 is number of wins with points. Same for lose1 and lose2
* roll is used to compare individual rolls*/
  
srand(time(NULL));
for(i=1; i <=100; i++)
{
roll=((rand()%(6-1+1)+1) + (rand()%(6-1+1)+1)); /*roll = points for one roll of two dice*/
  
if ( (roll==7) || (roll==11) )
win1++;
else if ( (roll==2) || (roll==3) || (roll==12))
lose1++;
else
{
do
{
points = roll;
roll2 = (rand()%(6-1+1)+1) + (rand()%(6-1+1));
}
while ( (roll2 != 7) && (roll2 != points) );

if (roll2 == 7)
lose2++;
  
else if (roll2 == points)
win2++;
}
}

printf( " You won on the first roll %d times. You lost on the first roll %d times. ", win1, lose1);
printf(" You won with points %d times. You lost with points %d times. ", win2, lose2);

return 0;

}

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