Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h>
- #include <cstdlib>
- using namespace std;
- int main(int argc, char *argv[])
- {
- srand (time(NULL));
- int score, hold, roll;
- int sim;
- double tsim, talley1, talley2, talley3, talley4, talley5, talley6, talley7;
- int x1,x2,x3,x4,x5;
- double sum1,sum2,sum3,sum4,sum5,sum6, sum7;
- cout << "What value should we hold at? ";
- cin >> hold;
- cout << endl;
- cout << "Hold-at-N turn simulations? ";
- cin >> tsim;
- cout << endl;
- roll=0;
- talley1=0;
- talley2=0;
- talley3=0;
- talley4=0;
- talley5=0;
- talley6=0;
- talley7=0;
- srand (time(NULL));
- for (sim=0; sim < tsim; sim++)
- {
- for (score=0; score < hold;)
- {
- roll = rand()%6+1;
- if (roll == 1)
- {
- talley1 = talley1 + 1;
- break;
- }
- else if (roll >=2 && roll <=6)
- {
- score = score + roll;
- if (score == hold)
- {
- talley2 = talley2 + 1;
- break;
- }
- else if (score == hold + 1)
- {
- talley3 = talley3 + 1;
- break;
- }
- else if (score == hold + 2)
- {
- talley4 = talley4 + 1;
- break;
- }
- else if (score == hold + 3)
- {
- talley5 = talley5 + 1;
- break;
- }
- else if (score == hold + 4)
- {
- talley6 = talley6 + 1;
- break;
- }
- else if (score == hold + 5)
- {
- talley7 = talley7 + 1;
- break;
- }
- }
- }
- }
- sum1 = talley2 / tsim;
- sum2 = talley3 / tsim;
- sum3 = talley4 / tsim;
- sum4 = talley5 / tsim;
- sum5 = talley6 / tsim;
- sum6 = talley7 / tsim;
- sum7 = talley1 / tsim;
- cout << "Score Estimated probability" << endl;
- cout << "0 " << sum7 << endl;
- cout << hold << " " << sum1 << endl;
- cout << hold + 1 << " " << sum2 << endl;
- cout << hold + 2 << " " << sum3 << endl;
- cout << hold + 3 << " " << sum4 << endl;
- cout << hold + 4 << " " << sum5 << endl;
- cout << hold + 5 << " " << sum6 << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement