diff options
author | RossTheRoss <msattr@gmail.com> | 2019-02-23 18:23:41 -0600 |
---|---|---|
committer | RossTheRoss <msattr@gmail.com> | 2019-02-23 18:23:41 -0600 |
commit | fd1296f97b53490c1bb5a3152da38c6a6c01048a (patch) | |
tree | fae15f9b9bec041e7d1907760bd3b535d9498e52 /ee1301/wk3/hw3_directory | |
parent | Dividing by 0 is a no (diff) | |
download | homework-fd1296f97b53490c1bb5a3152da38c6a6c01048a.tar homework-fd1296f97b53490c1bb5a3152da38c6a6c01048a.tar.gz homework-fd1296f97b53490c1bb5a3152da38c6a6c01048a.tar.bz2 homework-fd1296f97b53490c1bb5a3152da38c6a6c01048a.tar.lz homework-fd1296f97b53490c1bb5a3152da38c6a6c01048a.tar.xz homework-fd1296f97b53490c1bb5a3152da38c6a6c01048a.tar.zst homework-fd1296f97b53490c1bb5a3152da38c6a6c01048a.zip |
AHHHHHHHHHHHHHHHHHHHH
Diffstat (limited to 'ee1301/wk3/hw3_directory')
-rw-r--r-- | ee1301/wk3/hw3_directory/strap012_HW3A.cpp | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/ee1301/wk3/hw3_directory/strap012_HW3A.cpp b/ee1301/wk3/hw3_directory/strap012_HW3A.cpp index fd051fd..e22ef89 100644 --- a/ee1301/wk3/hw3_directory/strap012_HW3A.cpp +++ b/ee1301/wk3/hw3_directory/strap012_HW3A.cpp @@ -11,33 +11,32 @@ One-armed Bandit Simulator #include <iostream> #include <stdlib.h> #include <cmath> -#include <iomanip> +#include <iomanip> using namespace std; + int spin_the_wheel(int d, int w) { int spinOG, spinNew; spinOG = rand() % d + 1; - for (int i=w; i>0; i--) { + for (int i=1; i<w; i++) { spinNew = rand() % d + 1; - if (spinNew==spinOG) { - //Do nothing - } else { + if (spinNew!=spinOG) { return 0; } } return 1; } int main () { - long n=0; - int m=0; - float d= 3; - float w= 9; - for (n; n<=1000000; n++) { - m = spin_the_wheel(d,w); - if (m==1) { - m++; - } + long n = 0; + int m = 0; + int test; + int w = 3; + int d = 9; + for (n; n <= 1000; n++) + { + test = spin_the_wheel(d, w); + m+=test; } cout << "w=" << w << ", d=" << d; - cout << ": Simulated probability = m/n = " << (m/n)*100 << ". "; - cout << "Theoretical probability = " << (d/pow(d,w))*100 << "." << endl; + cout << ": Simulated probability = m/n = " << (m/n)*100 << "%. "; + cout << "Theoretical probability = " << (d/(pow(d,w)))*100 << "%." << endl; }
\ No newline at end of file |