aboutsummaryrefslogtreecommitdiffstats
path: root/ee1301/wk3/hw3_directory/strap012_HW3A.cpp
diff options
context:
space:
mode:
authorRossTheRoss <msattr@gmail.com>2019-02-26 14:52:59 -0600
committerRossTheRoss <msattr@gmail.com>2019-02-26 14:52:59 -0600
commit9e5fe835e5f89ed1031d1a437e8db54df289ba45 (patch)
tree81def966e89c557d5870c119d84cdab887de634d /ee1301/wk3/hw3_directory/strap012_HW3A.cpp
parentS (diff)
downloadhomework-9e5fe835e5f89ed1031d1a437e8db54df289ba45.tar
homework-9e5fe835e5f89ed1031d1a437e8db54df289ba45.tar.gz
homework-9e5fe835e5f89ed1031d1a437e8db54df289ba45.tar.bz2
homework-9e5fe835e5f89ed1031d1a437e8db54df289ba45.tar.lz
homework-9e5fe835e5f89ed1031d1a437e8db54df289ba45.tar.xz
homework-9e5fe835e5f89ed1031d1a437e8db54df289ba45.tar.zst
homework-9e5fe835e5f89ed1031d1a437e8db54df289ba45.zip
Rearrange functions
Diffstat (limited to 'ee1301/wk3/hw3_directory/strap012_HW3A.cpp')
-rw-r--r--ee1301/wk3/hw3_directory/strap012_HW3A.cpp38
1 files changed, 19 insertions, 19 deletions
diff --git a/ee1301/wk3/hw3_directory/strap012_HW3A.cpp b/ee1301/wk3/hw3_directory/strap012_HW3A.cpp
index b10c296..c164829 100644
--- a/ee1301/wk3/hw3_directory/strap012_HW3A.cpp
+++ b/ee1301/wk3/hw3_directory/strap012_HW3A.cpp
@@ -14,6 +14,25 @@ One-armed Bandit Simulator
#include <iomanip>
using namespace std;
+int main () {
+ srand(88888888); //Seeds the RNG of the program to a constant of eight 8s
+ int w, d, winCount, winTest;
+ for (w=3; w<=6; w++) {
+ winCount=0;
+ for (d=9; d<=27; d++) {
+ winCount=0;
+ for (long n=1000000; n>0; n--) {
+ int winTest = spin_the_wheels(d, w);
+ winCount+=winTest;
+ }
+ cout << "w=" << w << ", d=" << d
+ << ": Simulated probability = m/n = " << (winCount / 1000000.0) * 100.0 << "%. "
+ << "Theoretical probability = " << (d / (pow(d, w))) * 100 << "%." << endl;
+ d+=2;
+ }
+ }
+}
+
// Function: spin_the_wheels
// ---------------------------
// Simulates the one-armed bandit from the previous HW
@@ -36,23 +55,4 @@ int spin_the_wheels(int d, int w) {
} else {
return 0;
}
-}
-
-int main () {
- srand(88888888); //Seeds the RNG of the program to a constant of eight 8s
- int w, d, winCount, winTest;
- for (w=3; w<=6; w++) {
- winCount=0;
- for (d=9; d<=27; d++) {
- winCount=0;
- for (long n=1000000; n>0; n--) {
- int winTest = spin_the_wheels(d, w);
- winCount+=winTest;
- }
- cout << "w=" << w << ", d=" << d
- << ": Simulated probability = m/n = " << (winCount / 1000000.0) * 100.0 << "%. "
- << "Theoretical probability = " << (d / (pow(d, w))) * 100 << "%." << endl;
- d+=2;
- }
- }
} \ No newline at end of file