From 89ccbf439aef1d59d327badb741acde1623df4e6 Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Tue, 26 Feb 2019 13:47:46 -0600 Subject: MEANINGFUL C O M M E N T S --- ee1301/wk3/hw3_directory/strap012_HW3A.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'ee1301/wk3/hw3_directory/strap012_HW3A.cpp') 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; i0; 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; } } -- cgit v1.2.3