### Help getting dice to roll 10000 times.

I have to write a program that rolls 2 dice 10000 times in a game of craps and calculate the odds of winning and losing.
I have the program working to 1 roll but honestly i cant figure out how to get it to roll multiple times.

Thanks! Heres the code so far:

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384`` `````` #include #include #include #include #include #include #include using namespace std; int diceroll(); //funtion reference //global variables int dice1; int dice2; int rollSum; int sum; int rollPoint; double oddslosing; double odds; string status; int w = 0; //wins int l = 0; //lose int main() { sum = diceroll(); switch (sum) //switch for numbers { case 2: case 3: case 12: status = "lose"; ++l; break; case 7: case 11: status = "win"; ++w; break; default: status = "point"; rollPoint = sum; break; } while (status == "point") //point loop { sum = diceroll(); if (sum == rollPoint) status = "win"; else if (sum == 7) status = "lose"; else status = "point"; } if (status == "win") ++w; if (status == "lose") ++l; odds = ((double)w/(w+l)); oddslosing = ((double)l/(w+l)); cout<< "odds of winning: "<
Last edited on
like this perhaps?

i ran it 10 million times for kicks and got
win: .535538
lose: .464462
neat program =)

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788`` ``````#include #include #include #include #include #include #include using namespace std; int diceroll(); //funtion reference //global variables int dice1; int dice2; int rollSum; int sum; int rollPoint; double oddslosing; double odds; string status; int w = 0; //wins int l = 0; //lose int main() { for (int i=0; i<10000; ++i) { sum = diceroll(); switch (sum) //switch for numbers { case 2: case 3: case 12: status = "lose"; ++l; break; case 7: case 11: status = "win"; ++w; break; default: status = "point"; rollPoint = sum; break; } while (status == "point") //point loop { sum = diceroll(); if (sum == rollPoint) status = "win"; else if (sum == 7) status = "lose"; else status = "point"; } if (status == "win") ++w; if (status == "lose") ++l; } odds = ((double)w/(w+l)); oddslosing = ((double)l/(w+l)); cout<< "odds of winning: "<
Last edited on
Perfect! Much appreciated!

Thanks! :D
Topic archived. No new replies allowed.