aboutsummaryrefslogtreecommitdiffstats
path: root/ee1301/wk3/hw3_directory/strap012_HW3A.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ee1301/wk3/hw3_directory/strap012_HW3A.cpp')
-rw-r--r--ee1301/wk3/hw3_directory/strap012_HW3A.cpp23
1 files changed, 11 insertions, 12 deletions
diff --git a/ee1301/wk3/hw3_directory/strap012_HW3A.cpp b/ee1301/wk3/hw3_directory/strap012_HW3A.cpp
index 8ee7a55..453af2d 100644
--- a/ee1301/wk3/hw3_directory/strap012_HW3A.cpp
+++ b/ee1301/wk3/hw3_directory/strap012_HW3A.cpp
@@ -16,36 +16,35 @@ using namespace std;
int spin_the_wheel(int d, int w) {
int spinOG=0, spinNew=0, win=0;
- spinOG = ( (rand() % d) + 1);
+ spinOG = ( (rand() % d) + 1); //Original spin is always the same
for (int i=0; i<w; i++) {
- //spinOG = ( (rand() % d) + 1);
spinNew = ( (rand() % d) + 1);
if (spinOG==spinNew) {
win++;
}
}
- if (win==w) {
- return 1;
+ if (win==w) { //The only win condition is if every wheel matches
+ return 1; //"win"
} else {
- return 0;
+ return 0; //"loss"
}
}
int main () {
- srand(88888888); //See
- int w, d, m, test;
+ srand(88888888); //Seeds the RNG of the program to a constant of eight 8s
+ int w, d, m, winTest; //'w' is for spinner count, 'd' is the number of options on the spinner
for (w=3; w<=6; w++) {
m=0;
for (d=9; d<=27; d++) {
m=0;
- for (long long n=1000000; n>0; n--) {
- int test = spin_the_wheel(d, w);
- m+=test;
+ for (long n=1000000; n>0; n--) {
+ int winTest = spin_the_wheel(d, w);
+ m+=winTest;
}
double win=m;
cout << "w=" << w << ", d=" << d
- << ": Simulated probability = m/n = " << (win / 100000.0) * 100.0 << "%. "
- << "Theoretical probability = " << (d / (pow(d, w))) * 100 << "%." << endl;
+ << ": Simulated probability = m/n = " << (win / 100000.0) * 100.0 << "%. " //Note that 100,000!=1,000,000
+ << "Theoretical probability = " << (d / (pow(d, w))) * 100 << "%." << endl; //This is because otherwise the percentage was off by a factor of 10
d+=2;
}
}