468,513 Members | 984 Online

# Can I get help with code for game of craps 5
i have this code that plays the game of craps, but i need to be able to take how much they brought and how much they want to bet. show the number on the dice and tell them it they won or lose and what their money is after their roll. and have to ask if they want to play again.

#include <iostream>
#include <cstdlib>
#include <time.h>

using namespace std;

const int NUM_GAMES = 10000;

// Function prototypes
int roll_dice();

// ======================
// roll_dice
// Simulates rolling two six-sided dice
// and returns the sum.
// ======================
//roll dice
int dice1, dice2;
int roll_dice()

{
int sum;

dice1=(rand()%6);
dice2=(rand()%6);

sum=(dice1 + dice2 + 2);
//return the sums of the dice
return sum;

}

// ======================
// main function
// ======================
int main()
{
// Variable declarations
int numWins = 0;
int numLosses = 0;
int i;
int roll;
int point;
int sum;

// Initialize random number generator using
// the current value of the clock
srand(time(NULL));
for (i=0; i<NUM_GAMES; i++)
{
roll=roll_dice();

//roll dice
//see what the dice equal
if ((sum == 7) || (sum == 11))
{
numWins++;
}
else if((sum == 2)|| (sum == 3) || (sum == 12))
{
numLosses++;
}
else
//set sum to points
{
point=roll;
do
{
roll=roll_dice();
if (roll==7)
{
numLosses++;
}
else if (roll==point)
{
numWins++;
}
}while ((point != roll) && (roll!=7));
}
}
}

// Output probability of winning
cout << "In the simulation, we won " << numWins <<
" times and lost " << numLosses << " times, " <<
" for a probability of " <<
static_cast<double>(numWins) / (numWins+numLosses) <<
endl << endl;
system("Pause");
return 0;
}
Sep 21 '06 #1
1 6283 tyreld
144 100+
The following are simple examples of reading and writing using cout and cin.

Expand|Select|Wrap|Line Numbers
1. #include <iostream>
2. using namespace std;
3.
4. int main(int argc, char **argv)
5. {
6. int a = 5;
7.
8. // Print value to screen
9. cout << "The value of \"a\" is : " << a << endl;
10.
11. // Read in new value for a
12. cout << "Enter an integer : ";
13. cout.flush();
14. cin >> a;
15.
16. // Print new value to screen
17. cout << "The new value of \"a\" is : " << a << endl;
18.
19. return 0;
20. }
21.
Sep 21 '06 #2

### Post your reply

Sign in to post your reply or Sign up for a free account.

### Similar topics

 5 posts views Thread by Lt | last post: by reply views Thread by dnphamus13 | last post: by 1 post views Thread by Jerry Fleming | last post: by 7 posts views Thread by Gasten | last post: by reply views Thread by rocky666 | last post: by 2 posts views Thread by mer000 | last post: by 2 posts views Thread by vertozia | last post: by 2 posts views Thread by shinerankin | last post: by 1 post views Thread by SerialChick | last post: by reply views Thread by NPC403 | last post: by reply views Thread by slotstar | last post: by 7 posts views Thread by isladogs | last post: by reply views Thread by captainhaddock | last post: by reply views Thread by sakshijain10388 | last post: by 1 post views Thread by fmendoza | last post: by 1 post views Thread by sonnet | last post: by 1 post views Thread by hwsilver | last post: by reply views Thread by yuyenews | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.