For a class in C programming I have been asked to create a dice game. Here are the requirements.
A player rolls two dice. Each die has six 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 is calculated. If the sum is 7 or 11 on the first throw, the player wins. If the sum is 2,3, or 12 on the first throw (called “craps”), the player loses (i.e., the “house” wins). If the sum is 4,5,6,8,9, or 10 on the first throw, then that sum becomes the player’s “points.” To win, you must continue rolling the dice until you “make your points.” The player loses by rolling a 7 before making the points.
Make a program to simulate the game of craps for 100 times and print number of the wins in first roll, lost in first roll, wins with points, and lost with points.
Here is my code so far, but I am having a difficult time to have the program save the and print at the end of the game the number of wins in the first roll, lost in first roll, wins with points, and lost with points. Any help would be appreciated.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
int main ()
{
int i,d1,d2,sumd;
double winf = 0, lostf = 0, winp = 0, lostp = 0;
printf("This program will simulate the game of craps for 100 times. ");
for (i=0; i<100; i++) {
d1 = rand()%6+1;
d2 = rand()%6+1;
sumd = d1 + d2;
if (sumd=7,11) {
printf("You rolled a 7 or an 11, you win. ");
winf++;
}
if (sumd=2,3,12) {
printf("You rolled a 12, a 3, or a 2, you lose. ");
lostf++;
}
if (sumd=4,5,6,8,9,10) {
d1 = rand()%6+1;
d2 = rand()%6+1;
sumd = d1 + d2;
if (sumd=7) {
printf("You rolled a 7, you lose. ");
lostp++;
}
if (sumd=4,5,6,8,9,10) {
printf("You rolled your points, you win. ");
winp++;
}
}
}
printf("First roll wins: %d, First roll loses: %d, Second roll wins: %d, Second roll loses: %d. ", winf, lostf, winp, lostp);
}