So I need to wright a program that does this (But I have run into some issues any pointers, helps or suggestions would be greatly appreciated):
Write a program to simulate the casino game "craps".
It should play 1,000,000 games so that you can compute the
probability(%) of the "player" winning and the "house" winning.
The rules are:
Player rolls two dice.
When the sum is 7 or 11 on first throw, player wins.
When the sum is 2, 3, or 12 on first throw, "house" wins.
When the sum is 4,5,6,8,9, or 10 on first throw,
that sum becomes the player's "point".
Now, to win the player must continue rolling the dice until he
makes "point"; however should he roll a 7 then the "house" wins.
That concludes the game.
~ also how would I make it when the dice roles a "point" number to tell it to role the dice agin?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int dice1;
int dice2;
int sum_of_dice;
int point;
int number_of_times_played;
int main()
{
sum_of_dice = dice1 + dice2;
srand(time(0));
do
{
dice1 = rand() % 6 + 1;
dice2 = rand() % 6 + 1;
if (sum_of_dice == 7 || sum_of_dice == 11)
{
cout << "Congratulations you have won!" << endl;
}
else if (sum_of_dice == 2 || sum_of_dice == 3 || sum_of_dice == 12)
{
cout << "Better luck next time the house has one!" << endl;
}
else (sum_of_dice == 4 || sum_of_dice == 5 || sum_of_dice == 6 || sum_of_dice == 8 || sum_of_dice == 9 || sum_of_dice == 10);
{
cout << "Your point is now: " << sum_of_dice << endl;
// What should I put here to make it roll the dice agin and start over?
}
} while (number_of_times_played != 1);
return 0;
}//End Code!
|