Guest User

Untitled

a guest
Feb 21st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. #define MILLION 1000000
  8.  
  9. int main(void)
  10. {
  11.  
  12.     int chance[6] = {0};
  13.  
  14.     // seed with random time
  15.     srand(time(NULL));
  16.  
  17.     // random number 1 - 6
  18.     int rand_num;
  19.  
  20.     for (int i = 0; i < MILLION; i++) {
  21.         rand_num = rand() % 6 + 1;
  22.         chance[rand_num-1]++;
  23.     }
  24.  
  25.     for (int i = 0; i < 6; i++) {
  26.         cout << "probablity of " <<  i+1 << " is " << static_cast<double>(chance[i])/MILLION << endl;
  27.     }
  28.  
  29.     // pause before exit
  30.     cin.get();
  31.     return 0;
  32. }
Add Comment
Please, Sign In to add comment