Advertisement
Guest User

Untitled

a guest
Sep 24th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3. #include <cstdlib>
  4. using namespace std;
  5.  
  6. int main(int argc, char *argv[])
  7. {
  8. srand (time(NULL));
  9. int score, hold, roll;
  10. int sim;
  11. double tsim, talley1, talley2, talley3, talley4, talley5, talley6, talley7;
  12. int x1,x2,x3,x4,x5;
  13. double sum1,sum2,sum3,sum4,sum5,sum6, sum7;
  14. cout << "What value should we hold at? ";
  15. cin >> hold;
  16. cout << endl;
  17. cout << "Hold-at-N turn simulations? ";
  18. cin >> tsim;
  19. cout << endl;
  20.  
  21. roll=0;
  22. talley1=0;
  23. talley2=0;
  24. talley3=0;
  25. talley4=0;
  26. talley5=0;
  27. talley6=0;
  28. talley7=0;
  29.  
  30. srand (time(NULL));
  31.  
  32. for (sim=0; sim < tsim; sim++)
  33. {
  34. for (score=0; score < hold;)
  35. {
  36. roll = rand()%6+1;
  37.  
  38. if (roll == 1)
  39. {
  40. talley1 = talley1 + 1;
  41. break;
  42.  
  43. }
  44. else if (roll >=2 && roll <=6)
  45. {
  46. score = score + roll;
  47.  
  48. if (score == hold)
  49. {
  50. talley2 = talley2 + 1;
  51. break;
  52. }
  53. else if (score == hold + 1)
  54. {
  55. talley3 = talley3 + 1;
  56. break;
  57. }
  58. else if (score == hold + 2)
  59. {
  60. talley4 = talley4 + 1;
  61. break;
  62. }
  63. else if (score == hold + 3)
  64. {
  65. talley5 = talley5 + 1;
  66. break;
  67. }
  68. else if (score == hold + 4)
  69. {
  70. talley6 = talley6 + 1;
  71. break;
  72. }
  73. else if (score == hold + 5)
  74. {
  75. talley7 = talley7 + 1;
  76. break;
  77. }
  78.  
  79.  
  80. }
  81. }
  82. }
  83. sum1 = talley2 / tsim;
  84. sum2 = talley3 / tsim;
  85. sum3 = talley4 / tsim;
  86. sum4 = talley5 / tsim;
  87. sum5 = talley6 / tsim;
  88. sum6 = talley7 / tsim;
  89. sum7 = talley1 / tsim;
  90.  
  91. cout << "Score Estimated probability" << endl;
  92. cout << "0 " << sum7 << endl;
  93. cout << hold << " " << sum1 << endl;
  94. cout << hold + 1 << " " << sum2 << endl;
  95. cout << hold + 2 << " " << sum3 << endl;
  96. cout << hold + 3 << " " << sum4 << endl;
  97. cout << hold + 4 << " " << sum5 << endl;
  98. cout << hold + 5 << " " << sum6 << endl;
  99.  
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement