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;
}