Advertisement
Guest User

Untitled

a guest
Jul 13th, 2018
849
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <tgmath.h>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. float PERCENT;
  9. cout << "Whats the chance that you get a X% drop from 100 / X tries? (1% in 100, 0,5% in 200)" << endl << "Input the percentage chance for an item: ";
  10. cin >> PERCENT;
  11. int RATE = ceil(100.0 / PERCENT);
  12. int foundAmount, searchedAmount;
  13. foundAmount = searchedAmount = 0;
  14. srand(time(NULL));
  15. for(int k = 0; k < 1000000; k++) { //I have put an insane number here so it's very accurate.
  16. for(int i = 0; i < RATE; i++) {
  17. int number = rand()%100;
  18.  
  19. if (number < PERCENT) {
  20. foundAmount++;
  21. break;
  22. }
  23. }
  24.  
  25. searchedAmount++;
  26. }
  27.  
  28. cout << (foundAmount/(float)searchedAmount) * 100 << "%" << endl;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement