Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7419189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:01:06+00:00 2026-05-29T08:01:06+00:00

Purpose of this code: simulate 100 games of CRAPS and record the # of

  • 0

Purpose of this code: simulate 100 games of CRAPS and record the # of first round losses, first round wins, second round losses PLUS points, and second round wins PLUS points.

Those of you not familiar with the rules of CRAPS; you basically roll two die, if the result is anyhting other than a total of 2, 3, or 12, you get to roll again (the number you rolled that turn is preserved and added to your points). If you roll a 7 or 11 you automatically win.

This is where i’m at so far:

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

int main ()
{
int i,d1,d2,sumd,sumd2;
double winf = 0, lostf = 0, winp = 0, lostp = 0;
printf("This program will simulate the game of craps for 100 times.\n");

for (i=0; i<100; i++) {
    d1 = rand()%6+1;
    d2 = rand()%6+1;
    sumd = d1 + d2;

    if (sumd==7 || sumd==11) {
        printf("You rolled a 7 or an 11, you win.\n");
        winf++;
    }
    if (sumd==2 || sumd==3 || sumd==12) {
        printf("You rolled a 12, a 3, or a 2, you lose.\n");
        lostf++;
    }
    if (sumd==4 || sumd==5 || sumd==6 || sumd==8 || sumd==9 || sumd==10) {
        while (1) {
            d1 = rand()%6+1;
            d2 = rand()%6+1;
            sumd2 = d1 + d2;

            if (sumd2==sumd){ 
                printf("You rolled your points, you win.\n");
                winp++;
            break;}
            if (sumd==7){ 
                printf("You rolled a 7, you lose.\n");
                lostp++;
            break;}
        }
    }
}

printf("First roll wins: %lf, First roll loses: %lf, Second roll wins: %lf, Second roll loses: %lf. ", winf, lostf, winp, lostp);
}

All i ask of you is that you give me options on how i can preserve those points to be printed at the end??

Moreover, i feel my code could be written better and less redundantly, suggestions?

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

int main ()
{
int i,d1,d2,sumd,sumd2;
double winf = 0, lostf = 0, winp = 0, lostp = 0;

printf("This program will simulate the game of craps for 100 times. Press any key to continue.\n");
//getchar();

for (i=0; i<100; i++) {
    d1 = rand()%6+1;
    d2 = rand()%6+1;
    sumd = d1 + d2;

switch(sumd){
    case 7:
    case 11:
        printf("You rolled %d, you win.\n", sumd);
        winf++;
        break;
    case 2:
    case 3:
    case 12:
        printf("You rolled %d, you lose.\n", sumd);
        lostf++;
        break;
    default:
        while (1) {
            d1 = rand()%6+1;
            d2 = rand()%6+1;
            sumd2 = d1 + d2;

            if (sumd2==sumd){ 
                printf("You rolled your points(%d), you win.\n",sumd);
                winp++;
            break;}
            if (sumd2==7){ 
                printf("You rolled a 7, you lose.\n");
                lostp++;
            break;}
        }
}

}
printf("First roll wins: %lf, First roll loses: %lf, Second roll wins: %lf, Second roll loses: %lf. \n", winf, lostf, winp, lostp);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T08:01:07+00:00Added an answer on May 29, 2026 at 8:01 am

    Your solution of putting the results in ints to print at the end looks reasonable. If I’m understanding the question right, it seems winp and lostp should add sumd2 instead of just incrementing. Or is it already working ok and I’m misreading the question?

    You might also want to look at the switch statement:

    switch(sumd){
        case 7:
        case 11:
            //existing code goes here
            break;
    
        case 2:
        case 3:
        case 12:
            //more existing code
            break;
    
        default:
            //code for games that don't end on the first turn
            break;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The purpose of this code is to pull upgrade.zip from a central server, extract
Quick question, What have I done wrong here. The purpose of this code is
What is the purpose of these java.lang.annotation imports in this code? Why are they
The purpose of this code is to send emails in the GridView to individuals
I have the following code for google maps. The purpose of this code is
Could someone explain to me what purpose this code serves? I found it in
The purpose of this code is to show a list of string with a
The purpose of this code is just separate the config data. If i use
How can I improve this? the purpose of this code is to be used
new AutoResetEvent(false).WaitOne(Period); What is purpose of this code? Why not use Thread.Sleep instead?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.