summaryrefslogtreecommitdiff
path: root/5p25.cpp
diff options
context:
space:
mode:
authorOskar <[email protected]>2024-09-04 16:26:22 +0200
committerOskar <[email protected]>2024-09-04 16:26:22 +0200
commita577cee5a0b44aadadd2f0932a794310bb775a83 (patch)
treeafc64e84e2fb41f76101398f2f68d947a47217b5 /5p25.cpp
parentdebcd0caea344c8993c00b96d56b77ae72fff192 (diff)
more exercise
Diffstat (limited to '5p25.cpp')
-rw-r--r--5p25.cpp37
1 files changed, 37 insertions, 0 deletions
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;
+}