aboutsummaryrefslogtreecommitdiffstats
path: root/ee1301/wk3
diff options
context:
space:
mode:
authorRossTheRoss <msattr@gmail.com>2019-02-26 13:47:46 -0600
committerRossTheRoss <msattr@gmail.com>2019-02-26 13:47:46 -0600
commit89ccbf439aef1d59d327badb741acde1623df4e6 (patch)
tree3dd3474513dc88454ff3c7c45317cdf2ebf93040 /ee1301/wk3
parentMerge branches 'master' and 'master' of github.com:RosstheRoss/TestingFun (diff)
downloadhomework-89ccbf439aef1d59d327badb741acde1623df4e6.tar
homework-89ccbf439aef1d59d327badb741acde1623df4e6.tar.gz
homework-89ccbf439aef1d59d327badb741acde1623df4e6.tar.bz2
homework-89ccbf439aef1d59d327badb741acde1623df4e6.tar.lz
homework-89ccbf439aef1d59d327badb741acde1623df4e6.tar.xz
homework-89ccbf439aef1d59d327badb741acde1623df4e6.tar.zst
homework-89ccbf439aef1d59d327badb741acde1623df4e6.zip
MEANINGFUL C O M M E N T
S
Diffstat (limited to '')
-rw-r--r--ee1301/wk3/hw3_directory/strap012_HW3A.cpp23
-rw-r--r--ee1301/wk3/hw3_directory/strap012_HW3C.cpp15
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";
}
}