aboutsummaryrefslogtreecommitdiffstats
path: root/ee1301/wk6
diff options
context:
space:
mode:
authorMatthew Strapp <msattr@gmail.com>2019-04-14 12:03:20 -0500
committerMatthew Strapp <msattr@gmail.com>2019-04-14 12:03:20 -0500
commitf4a2e785a3debf75db94b21fadf2d84abc594f05 (patch)
tree844c18feb412a0db2d50de4e7ce32e6d10c8bff0 /ee1301/wk6
parentStart 6A (diff)
downloadhomework-f4a2e785a3debf75db94b21fadf2d84abc594f05.tar
homework-f4a2e785a3debf75db94b21fadf2d84abc594f05.tar.gz
homework-f4a2e785a3debf75db94b21fadf2d84abc594f05.tar.bz2
homework-f4a2e785a3debf75db94b21fadf2d84abc594f05.tar.lz
homework-f4a2e785a3debf75db94b21fadf2d84abc594f05.tar.xz
homework-f4a2e785a3debf75db94b21fadf2d84abc594f05.tar.zst
homework-f4a2e785a3debf75db94b21fadf2d84abc594f05.zip
Start 6B (much easier than 6A)
Diffstat (limited to '')
-rw-r--r--ee1301/wk6/hw6_directory/dice.cpp (renamed from ee1301/wk6/dice.cpp)0
-rw-r--r--ee1301/wk6/hw6_directory/strap012_HW6B.cpp29
2 files changed, 29 insertions, 0 deletions
diff --git a/ee1301/wk6/dice.cpp b/ee1301/wk6/hw6_directory/dice.cpp
index ebdb7d6..ebdb7d6 100644
--- a/ee1301/wk6/dice.cpp
+++ b/ee1301/wk6/hw6_directory/dice.cpp
diff --git a/ee1301/wk6/hw6_directory/strap012_HW6B.cpp b/ee1301/wk6/hw6_directory/strap012_HW6B.cpp
new file mode 100644
index 0000000..5b15ca0
--- /dev/null
+++ b/ee1301/wk6/hw6_directory/strap012_HW6B.cpp
@@ -0,0 +1,29 @@
+#include <iostream>
+
+int ff(int x);
+
+int main() {
+ int value = -1;
+ do {
+ std::cout << "Please enter a value of x: ";
+ std::cin >> value;
+ } while (value<0);
+ std::cout << "Beginning calculation of ff(x)...\n";
+ int ffx = ff(value);
+ std::cout << "Calcuation complete, ff(x) = " << ffx << std::endl;
+}
+
+int ff(int x) {
+ if (x > 1) {
+ if (x%2 == 0) {
+ std::cout << "Calling ff(" << x/2 << ")\n";
+ return x*ff(x/2);
+ } else {
+ std::cout << "Calling ff(" << x-2 << ")\n";
+ return x*ff(x-2);
+ }
+ } else {
+ std::cout << "Returning from ff(" << x << ") = 1\n";
+ return 1;
+ }
+}