Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <tgmath.h>
- using namespace std;
- int main()
- {
- float PERCENT;
- 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: ";
- cin >> PERCENT;
- int RATE = ceil(100.0 / PERCENT);
- int foundAmount, searchedAmount;
- foundAmount = searchedAmount = 0;
- srand(time(NULL));
- for(int k = 0; k < 1000000; k++) { //I have put an insane number here so it's very accurate.
- for(int i = 0; i < RATE; i++) {
- int number = rand()%100;
- if (number < PERCENT) {
- foundAmount++;
- break;
- }
- }
- searchedAmount++;
- }
- cout << (foundAmount/(float)searchedAmount) * 100 << "%" << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement