aboutsummaryrefslogtreecommitdiffstats
path: root/ee1301/wk3
diff options
context:
space:
mode:
authorRossTheRoss <msattr@gmail.com>2019-02-24 13:17:13 -0600
committerRossTheRoss <msattr@gmail.com>2019-02-24 13:17:13 -0600
commit5bcbeea329a54f9f054ff8f226d1b2df4d21a145 (patch)
tree3ec25eeb1958a422b980a89a7c75445075012e1e /ee1301/wk3
parentRage at 3A (diff)
downloadhomework-5bcbeea329a54f9f054ff8f226d1b2df4d21a145.tar
homework-5bcbeea329a54f9f054ff8f226d1b2df4d21a145.tar.gz
homework-5bcbeea329a54f9f054ff8f226d1b2df4d21a145.tar.bz2
homework-5bcbeea329a54f9f054ff8f226d1b2df4d21a145.tar.lz
homework-5bcbeea329a54f9f054ff8f226d1b2df4d21a145.tar.xz
homework-5bcbeea329a54f9f054ff8f226d1b2df4d21a145.tar.zst
homework-5bcbeea329a54f9f054ff8f226d1b2df4d21a145.zip
Finish 3A but 10s are hard
Diffstat (limited to 'ee1301/wk3')
-rw-r--r--ee1301/wk3/hw3_directory/strap012_HW3A.cpp37
1 files changed, 21 insertions, 16 deletions
diff --git a/ee1301/wk3/hw3_directory/strap012_HW3A.cpp b/ee1301/wk3/hw3_directory/strap012_HW3A.cpp
index 55e8f6c..8d75294 100644
--- a/ee1301/wk3/hw3_directory/strap012_HW3A.cpp
+++ b/ee1301/wk3/hw3_directory/strap012_HW3A.cpp
@@ -17,10 +17,11 @@ using namespace std;
int spin_the_wheel(int d, int w) {
int spinOG=0, spinNew=0, win=0;
- for (int i=1; i<=w; i++) {
+ //spinOG = ( (rand() % d) + 1);
+ for (int i=0; i<w; i++) {
spinOG = ( (rand() % d) + 1);
spinNew = ( (rand() % d) + 1);
- if (spinOG==spinNew) {
+ if (spinOG==spinNew) {
win++;
}
}
@@ -30,20 +31,24 @@ int spin_the_wheel(int d, int w) {
return 0;
}
}
+
int main () {
- srand(time(NULL));
- long n = 0;
- int m = 0;
- float test;
- int w = 3;
- int d = 9;
- for (n; n <= 1000000; n++)
- {
- test = spin_the_wheel(d, w);
- m+=test;
+ srand(10000);
+ int w, d, m, test;
+ for (w=3; w<=6; w++) {
+ m=0;
+ for (d=9; d<=27; d++) {
+ m=0;
+ for (long n=1000000; n>0; n--) {
+ int test = spin_the_wheel(d, w);
+ m+=test;
+ }
+ double win=m;
+ cout << fixed << setprecision(5)
+ << "w=" << w << ", d=" << d
+ << ": Simulated probability = m/n = " << (win / 1000000.0) * 100.0 << "%. "
+ << "Theoretical probability = " << (d / (pow(d, w))) * 100 << "%." << endl;
+ d+=2;
+ }
}
-
- cout << "w=" << w << ", d=" << d;
- cout << ": Simulated probability = m/n = " << (m/n)*100 << "%. ";
- cout << "Theoretical probability = " << (d/(pow(d,w)))*100 << "%." << endl;
} \ No newline at end of file