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 41 42 43
|
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
bool done(false);
int dice1(0), dice2(0), dicesum(0), point(0);
double win(0), percent(0);
unsigned seed = time(0);
srand(seed);
for (int i = 1; i <= 100000000; i++)
// so far, so good:
//NOW:
{
initialize done to false, point to zero
//start another loop here to repeat throwing the dice until you win or lose on the throw
while not done
{
roll and sum the dice
if the point is zero (first time through this loop):
{
decide whether you win (7 or 11) ,lose (2,3 or 12), if neither, set the point to the sum of the dice.
if you win or lose, <done> becomes true, win is incremented if throw wins
}
else //second and subsequent passes througn this loop until <done> is made true by win or loss
{
decide whether you win (by matching the point) or lose (throw a seven)
if you win or lose, <done> becomes true, win is incremented if throw matches point
}
} //end of "not done"
} // end of iterations (int i = 1; i <= 100000000; i++) loop
percent = win / 100000000; // probably need to multiply this by 100 to get percentage
cout << "Win Rate: " << percent << "%" << endl;
}
|