diff options
-rw-r--r-- | ee1301/wk6/hw6_directory/dice.cpp | 23 | ||||
-rw-r--r-- | ee1301/wk6/hw6_directory/strap012_HW6B.cpp | 12 |
2 files changed, 21 insertions, 14 deletions
diff --git a/ee1301/wk6/hw6_directory/dice.cpp b/ee1301/wk6/hw6_directory/dice.cpp index 7adefe5..8b41c0a 100644 --- a/ee1301/wk6/hw6_directory/dice.cpp +++ b/ee1301/wk6/hw6_directory/dice.cpp @@ -14,19 +14,22 @@ class Dice { private: int min; int max; - public: -// void roll(); + int roll(int min, int max); + void setMin(); int getMin(); + void setMax(); int getMax(); + Dice(); + Dice(int min, int max); }; -int main() -{ - srand(time(NULL)); // DO NOT WRITE THIS LINE AGAIN OR ANYWHERE ELSE +int main() { + int rounds; + Dice die[50]; + srand(time(0)); // DO NOT WRITE THIS LINE AGAIN OR ANYWHERE ELSE cout << "What do you want to roll? "; string s; getline(cin, s); - cin.ignore(); - cout << "How many rounds do you want to roll?"; + cout << "How many rounds do you want to roll? "; cin >> rounds; int* pairs = userInputParser(s); @@ -42,6 +45,8 @@ int main() for(int i=1; i < pairs[0]; i+=2) { cout << "["<<pairs[i]<<","<<pairs[i+1]<<"]" << endl; + die[i-1] = Dice(i,i+1); + cout << die.roll(pairs[i], pairs[i+1]); } } @@ -180,3 +185,7 @@ int* userInputParser(string s) { return dice; } + +int Dice::roll(int min, int max) { + return rand() % (max-min) + min; +} diff --git a/ee1301/wk6/hw6_directory/strap012_HW6B.cpp b/ee1301/wk6/hw6_directory/strap012_HW6B.cpp index 3426c52..d53ea08 100644 --- a/ee1301/wk6/hw6_directory/strap012_HW6B.cpp +++ b/ee1301/wk6/hw6_directory/strap012_HW6B.cpp @@ -5,23 +5,21 @@ #include <iostream> int ff(int x); - int main() { - int value; + int x; do { std::cout << "Please enter a value of x: "; - std::cin >> value; - } while (value<0); + std::cin >> x; + } while (x<0); std::cout << "Beginning calculation of ff(x)...\n"; - int ffx = ff(value); - std::cout << "Calcuation complete, ff(x) = " << ffx << std::endl; + std::cout << "Calcuation complete, ff(x) = " << ff(x) << std::endl; } // This function either returns 1 when x is one of two recrusive conditions depending on if x is even or odd. int ff(int x) { if (x > 1) { if (x%2 == 0) { - //x is even + // x is even std::cout << "Calling ff(" << x/2 << ")\n"; return x*ff(x/2); } else { |