diff options
Diffstat (limited to 'ee1301/wk3/hw3_directory')
-rw-r--r-- | ee1301/wk3/hw3_directory/strap012_HW3A.cpp | 23 | ||||
-rw-r--r-- | ee1301/wk3/hw3_directory/strap012_HW3C.cpp | 15 |
2 files changed, 16 insertions, 22 deletions
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; i<w; i++) { - //spinOG = ( (rand() % d) + 1); spinNew = ( (rand() % d) + 1); if (spinOG==spinNew) { win++; } } - if (win==w) { - return 1; + if (win==w) { //The only win condition is if every wheel matches + return 1; //"win" } else { - return 0; + return 0; //"loss" } } int main () { - srand(88888888); //See - int w, d, m, test; + srand(88888888); //Seeds the RNG of the program to a constant of eight 8s + int w, d, m, winTest; //'w' is for spinner count, 'd' is the number of options on the spinner for (w=3; w<=6; w++) { m=0; for (d=9; d<=27; d++) { m=0; - for (long long n=1000000; n>0; 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 <cmath> #include <iomanip> 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"; } } |