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 +++++++++++------------ ee1301/wk3/hw3_directory/strap012_HW3C.cpp | 15 +++++---------- 2 files changed, 16 insertions(+), 22 deletions(-) (limited to 'ee1301/wk3') 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; } } diff --git a/ee1301/wk3/hw3_directory/strap012_HW3C.cpp b/ee1301/wk3/hw3_directory/strap012_HW3C.cpp index 7267e02..69eb51f 100644 --- a/ee1301/wk3/hw3_directory/strap012_HW3C.cpp +++ b/ee1301/wk3/hw3_directory/strap012_HW3C.cpp @@ -13,23 +13,18 @@ Character Detection #include #include using namespace std; + char swapCase(char s) { char New; cout << "You entered " << s; - if (s >= 'a' && s <= 'z') - { + if (s >= 'a' && s <= 'z') { New= s - 32; cout << ", I respond with " << New; - } - else - { - if (s >= 'A' && s <= 'Z') - { + } else { + if (s >= 'A' && s <= 'Z') { New = s + 32; cout << ", I respond with " << New; - } - else - { + } else { cout << ", which is not a valid character"; } } -- cgit v1.2.3