Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- 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;
- }
- system("PAUSE");
- return 0;
- }
- double chance()
- {
- double num = ((double)rand()) / (double)RAND_MAX;
- return num;
- }
- double shoot(int destination)
- {
- int score = 0;
- double shot = chance();
- switch (destination)
- {
- case 10:
- if (shot < .5)
- score += 5;
- else if (shot >= .5 || shot < .9)
- score += 3;
- else if (shot >= .9 || shot < .95)
- score += 1;
- else if (shot >= .95 || shot < 1)
- score += 0;
- break;
- case 20:
- if (shot < .4)
- score += 5;
- else if (shot >= .4 || shot < .8)
- score += 3;
- else if (shot >= .8 || shot < .9)
- score += 1;
- else if (shot >= .9 || shot < 1)
- score += 0;
- break;
- case 30:
- if (shot < .3)
- score += 5;
- else if (shot >= .3 || shot < .6)
- score += 3;
- else if (shot >= .6 || shot < .75)
- score += 1;
- else if (shot >= .75 || shot < 1)
- score += 0;
- break;
- case 40:
- if (shot < .2)
- score += 5;
- else if (shot >= .2 || shot < .4)
- score += 3;
- else if (shot >= .4 || shot < .6)
- score += 1;
- else if (shot >= .6 || shot < 1)
- score += 0;
- break;
- case 50:
- if (shot < .1)
- score += 5;
- else if (shot >= .1 || shot < .2)
- score += 3;
- else if (shot >= .2 || shot < .45)
- score += 1;
- else if (shot >= .45 || shot < 1)
- score += 0;
- break;
- }
- return score;
- }
- void play()
- {
- int totalscore = 0;
- for (int i = 1; i <= 5; i++)
- {
- cout << "Distance " << (i*10) << ": " << shoot(i*10) << endl;
- totalscore += shoot(i*10);
- }
- cout << "------------------" << endl;
- cout << "Total Score: " << totalscore << " points" << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement