Advertisement
Guest User

Untitled

a guest
Oct 9th, 2015
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. double chance();
  8. double shoot(int distance);
  9. void play();
  10.  
  11. const double MAX = 1.0;
  12. int main()
  13. {
  14. int rounds = 1;
  15. int choice = 1;
  16. cout << "Welcome to Archery Shooting Simulation" << endl;
  17. while (choice != 0)
  18. {
  19. srand(time(NULL)); // Seeds a random number
  20. cout << "Round " << rounds << ":" << endl;
  21. play();
  22. rounds++;
  23.  
  24. cout << endl << "Enter 0 to exit, any other value to play again: ";
  25. cin >> choice;
  26. }
  27.  
  28. return 0;
  29. }
  30.  
  31. double chance()
  32. {
  33. double num = ((double)rand()) / (double)RAND_MAX;
  34. return num;
  35. }
  36.  
  37. double shoot(int destination)
  38. {
  39. double score = 0;
  40. double shot = chance();
  41. switch (destination)
  42. {
  43. case 10:
  44. if (shot < .5)
  45. return score = 5;
  46. else if (shot >= .5 && shot < .9)
  47. return score = 3;
  48. else if (shot >= .9 && shot < .95)
  49. return score = 1;
  50. else if (shot >= .95 && shot < 1)
  51. return score = 0;
  52. break;
  53. case 20:
  54. if (shot < .4)
  55. return score = 5;
  56. else if (shot >= .4 && shot < .8)
  57. return score = 3;
  58. else if (shot >= .8 && shot < .9)
  59. return score = 1;
  60. else if (shot >= .9 && shot < 1)
  61. return score = 0;
  62. break;
  63. case 30:
  64. if (shot < .3)
  65. return score = 5;
  66. else if (shot >= .3 && shot < .6)
  67. return score = 3;
  68. else if (shot >= .6 && shot < .75)
  69. return score = 1;
  70. else if (shot >= .75 && shot < 1)
  71. return score = 0;
  72. break;
  73. case 40:
  74. if (shot < .2)
  75. return score = 5;
  76. else if (shot >= .2 && shot < .4)
  77. return score = 3;
  78. else if (shot >= .4 && shot < .6)
  79. return score = 1;
  80. else if (shot >= .6 && shot < 1)
  81. return score = 0;
  82. break;
  83. case 50:
  84. if (shot < .1)
  85. return score = 5;
  86. else if (shot >= .1 && shot < .2)
  87. return score = 3;
  88. else if (shot >= .2 && shot < .45)
  89. return score = 1;
  90. else if (shot >= .45 && shot < 1)
  91. return score = 0;
  92. break;
  93. }
  94. }
  95.  
  96. void play()
  97. {
  98. int totalscore = 0;
  99. double zscore;
  100. for (int i = 1; i <= 5; i++)
  101. {
  102. zscore = shoot(i*10);
  103. cout << "Distance " << i*10 << ": " << zscore << endl;
  104. totalscore += zscore;
  105. }
  106. cout << "------------------" << endl;
  107. cout << "Total Score: " << totalscore << " points" << endl;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement