-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path7.17.cpp
More file actions
39 lines (28 loc) · 1.06 KB
/
7.17.cpp
File metadata and controls
39 lines (28 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Dice Rolling
#include <iostream>
#include <iomanip>
#include <ctime> // for seeding the PRNG
#include <cstdlib> // for PRNG
using namespace std;
#define TIMES_TO_ROLL 36000 // number of times dice must be rolled
#define SUM_ARRAY_SIZE 13 // will only use indices 2-12
int main(void){
// seed the Pseudo-Random Number Generator
srand(time(NULL));
unsigned short die1 = 0, die2 = 0; // the two dice rolled
unsigned short diceSums[SUM_ARRAY_SIZE] = {}; // array to hold the dice sums
for (int roll = 0; roll < TIMES_TO_ROLL; roll++){
// roll both dice
die1 = 1 + rand() % 6;
die2 = 1 + rand() % 6;
// tally the sum count in the array
diceSums[die1+die2]++;
}
// print the results, skipping first 2 indices
cout << "Following results were generated by 36,000 dice rolls" << endl;
cout << setw(5) << left << "Sum" << setw(10) << "Occurances" << endl;
for (int i=2; i<SUM_ARRAY_SIZE; i++){
cout << setw(5) << left << i << setw(10) << diceSums[i] << endl;
}
return 0;
}