summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--5p22.cpp31
-rw-r--r--5p23.cpp17
-rw-r--r--5p24.cpp21
-rw-r--r--5p25.cpp37
4 files changed, 106 insertions, 0 deletions
diff --git a/5p22.cpp b/5p22.cpp
new file mode 100644
index 0000000..9bc9a0f
--- /dev/null
+++ b/5p22.cpp
@@ -0,0 +1,31 @@
+#include <iostream>
+
+/*
+ *
+ * 5.22
+ *
+ *
+ */
+
+int get_size() {
+
+ return 2;
+}
+
+int main () {
+
+ begin:
+ int sz = get_size();
+ if (sz <= 0) {
+ goto begin;
+ }
+
+ for(int sz1 = get_size() ; sz1 <= 0 ; sz1 = get_size()) {}
+
+ int sz2 = get_size();
+ while(sz2 <= 0) {
+ sz2 = get_size();
+ }
+
+ return 0;
+}
diff --git a/5p23.cpp b/5p23.cpp
new file mode 100644
index 0000000..861cce0
--- /dev/null
+++ b/5p23.cpp
@@ -0,0 +1,17 @@
+#include <iostream>
+
+/*
+ *
+ * 5.23
+ *
+ *
+ */
+
+int main () {
+
+ int a = 0;
+ int b = 0;
+ std::cin >> a >> b;
+ std::cout << a / b << std::endl;
+ return 0;
+}
diff --git a/5p24.cpp b/5p24.cpp
new file mode 100644
index 0000000..d8a7bc9
--- /dev/null
+++ b/5p24.cpp
@@ -0,0 +1,21 @@
+#include <iostream>
+
+/*
+ *
+ * 5.24
+ *
+ *
+ */
+
+int main () {
+
+ int a = 0;
+ int b = 0;
+ std::cin >> a >> b;
+ if(b == 0) {
+ throw std::runtime_error("You cannot divide by 0!");
+ }
+
+ std::cout << a / b << std::endl;
+ return 0;
+}
diff --git a/5p25.cpp b/5p25.cpp
new file mode 100644
index 0000000..6a3fbf6
--- /dev/null
+++ b/5p25.cpp
@@ -0,0 +1,37 @@
+#include <iostream>
+#include <stdexcept>
+
+/*
+ *
+ * 5.23
+ *
+ *
+ */
+
+int main () {
+
+ int a = 0;
+ int b = 0;
+ bool d = true;
+ while(d) {
+ d = false;
+ try {
+ std::cin >> a >> b;
+ if(b == 0) {
+ throw std::runtime_error("divide by 0!");
+ }
+
+ std::cout << a / b << std::endl;
+ } catch(std::runtime_error &err) {
+ std::cout << err.what() << "\nTry again? Y/N " << std::endl;
+ char c = 0;
+ std::cin >> c;
+ if(c == 'Y' || c == 'y') {
+ d = true;
+ }
+ }
+
+ }
+
+ return 0;
+}