Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <cstdlib>
- using namespace std;
- double chance();
- double shoot(int distance);
- void play();
- const double MAX = 1.0;
- int main()
- {
- int rounds = 1;
- int choice = 1;
- cout << "Welcome to Archery Shooting Simulation" << endl;
- while (choice != 0)
- {
- srand(time(NULL)); // Seeds a random number
- cout << "Round " << rounds << ":" << endl;
- play();
- rounds++;
- cout << endl << "Enter 0 to exit, any other value to play again: ";
- cin >> choice;
- }
- return 0;
- }
- double chance()
- {
- double num = ((double)rand()) / (double)RAND_MAX;
- return num;
- }
- double shoot(int destination)
- {
- double score = 0;
- double shot = chance();
- switch (destination)
- {
- case 10:
- if (shot < .5)
- return score = 5;
- else if (shot >= .5 && shot < .9)
- return score = 3;
- else if (shot >= .9 && shot < .95)
- return score = 1;
- else if (shot >= .95 && shot < 1)
- return score = 0;
- break;
- case 20:
- if (shot < .4)
- return score = 5;
- else if (shot >= .4 && shot < .8)
- return score = 3;
- else if (shot >= .8 && shot < .9)
- return score = 1;
- else if (shot >= .9 && shot < 1)
- return score = 0;
- break;
- case 30:
- if (shot < .3)
- return score = 5;
- else if (shot >= .3 && shot < .6)
- return score = 3;
- else if (shot >= .6 && shot < .75)
- return score = 1;
- else if (shot >= .75 && shot < 1)
- return score = 0;
- break;
- case 40:
- if (shot < .2)
- return score = 5;
- else if (shot >= .2 && shot < .4)
- return score = 3;
- else if (shot >= .4 && shot < .6)
- return score = 1;
- else if (shot >= .6 && shot < 1)
- return score = 0;
- break;
- case 50:
- if (shot < .1)
- return score = 5;
- else if (shot >= .1 && shot < .2)
- return score = 3;
- else if (shot >= .2 && shot < .45)
- return score = 1;
- else if (shot >= .45 && shot < 1)
- return score = 0;
- break;
- }
- }
- void play()
- {
- int totalscore = 0;
- double zscore;
- for (int i = 1; i <= 5; i++)
- {
- zscore = shoot(i*10);
- cout << "Distance " << i*10 << ": " << zscore << endl;
- totalscore += zscore;
- }
- cout << "------------------" << endl;
- cout << "Total Score: " << totalscore << " points" << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement