Advertisement
Guest User

Untitled

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