aboutsummaryrefslogtreecommitdiffstats
path: root/ee1301/wk6/hw6_directory
diff options
context:
space:
mode:
authorRossTheRoss <msattr@gmail.com>2019-04-17 12:29:54 -0500
committerRossTheRoss <msattr@gmail.com>2019-04-17 12:29:54 -0500
commit1780c94458e5f886a48c69b42bf578f1f6ed9ab5 (patch)
treed44544ddd3a2c1ad01e2d2e8ae9573533b561488 /ee1301/wk6/hw6_directory
parentFix one problem, cause several more (diff)
downloadhomework-1780c94458e5f886a48c69b42bf578f1f6ed9ab5.tar
homework-1780c94458e5f886a48c69b42bf578f1f6ed9ab5.tar.gz
homework-1780c94458e5f886a48c69b42bf578f1f6ed9ab5.tar.bz2
homework-1780c94458e5f886a48c69b42bf578f1f6ed9ab5.tar.lz
homework-1780c94458e5f886a48c69b42bf578f1f6ed9ab5.tar.xz
homework-1780c94458e5f886a48c69b42bf578f1f6ed9ab5.tar.zst
homework-1780c94458e5f886a48c69b42bf578f1f6ed9ab5.zip
(Almost) Finish 6A
Diffstat (limited to '')
-rw-r--r--ee1301/wk6/hw6_directory/dice.cpp51
1 files changed, 31 insertions, 20 deletions
diff --git a/ee1301/wk6/hw6_directory/dice.cpp b/ee1301/wk6/hw6_directory/dice.cpp
index 8902e0b..f2f983f 100644
--- a/ee1301/wk6/hw6_directory/dice.cpp
+++ b/ee1301/wk6/hw6_directory/dice.cpp
@@ -16,7 +16,9 @@ private:
int min;
int max;
public:
- int roll(int min, int max);
+ int roll(int min, int max) {
+ return rand() % (max-min+1) + min;
+ };
Dice() { //Default constructor for debugging purposes
min=1;
max=1;
@@ -29,9 +31,10 @@ public:
int main() {
int rounds;
- Dice die[50];
- int roll[50];
- int max=0, min=0;
+ Dice die[maxNumDie];
+ int roll[maxNumDie];
+ int max=0, min=999999, sum=0, sample=0;
+ double avg;
srand(time(0)); // DO NOT WRITE THIS LINE AGAIN OR ANYWHERE ELSE
cout << "What do you want to roll? ";
string s;
@@ -49,19 +52,31 @@ int main() {
// first_die_end,
// second_die_start,
// ... }
- for(int i=1; i < pairs[0]; i+=2)
- {
- cout << "["<<pairs[i]<<","<<pairs[i+1]<<"]" << endl;
- die[i - 1] = Dice(pairs[i], pairs[i + 1]);
+ double numRolls=0;
+ for (int j=0; j<rounds; j++) {
+ int curRoll=0;
+ numRolls+=1.0;
+ for(int i=1; i < pairs[0]; i+=2) {
+// cout << "["<<pairs[i]<<","<<pairs[i+1] <<"]" << endl;
+ die[i-1] = Dice(pairs[i], pairs[i + 1]);
roll[i-1] = die[i-1].roll(pairs[i], pairs[i+1]);
- if (roll[i-3] > roll[i-1]) {
- min = roll[i-1];
- }
- if (roll[i-3] < roll[i-1]) {
- max = roll[i-1];
- }
- }
- cout << max << " " << min;
+ curRoll += roll[i-1];
+ }
+
+ if (curRoll > max) {
+ max = curRoll;
+ }
+ if (curRoll < min) {
+ min = curRoll;
+ }
+ sum+=curRoll;
+ }
+ avg = sum / numRolls;
+ cout << "Sample roll: " << sample << endl
+ << "Minimum roll: " << min << endl
+ << "Maximum roll: " << max << endl
+ << "Average roll: " << avg << endl;
+
}
@@ -199,7 +214,3 @@ int* userInputParser(string s) {
return dice;
}
-
-int Dice::roll(int min, int max) {
- return rand() % (max-min) + min;
-}