aboutsummaryrefslogtreecommitdiff
path: root/week08/Exercise6.cpp
diff options
context:
space:
mode:
authorSyndamia <kamen@syndamia.com>2024-04-22 15:43:49 +0300
committerSyndamia <kamen@syndamia.com>2024-04-22 15:43:49 +0300
commitf3406754705e508f57768d3d0d8e457ff5b7620c (patch)
tree9f8743208732c21d5dcb51302feb29058edd8e58 /week08/Exercise6.cpp
parentf7ed9a8a6c31b17d54d2f37cc0f12b64f8e4b6d2 (diff)
downloadoop-2023-solutions-f3406754705e508f57768d3d0d8e457ff5b7620c.tar
oop-2023-solutions-f3406754705e508f57768d3d0d8e457ff5b7620c.tar.gz
oop-2023-solutions-f3406754705e508f57768d3d0d8e457ff5b7620c.zip
[w8] Added exercise descriptions and solutions to ex 1-7
Diffstat (limited to 'week08/Exercise6.cpp')
-rw-r--r--week08/Exercise6.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/week08/Exercise6.cpp b/week08/Exercise6.cpp
new file mode 100644
index 0000000..22594a0
--- /dev/null
+++ b/week08/Exercise6.cpp
@@ -0,0 +1,27 @@
+#include "Exercise6.h"
+#include <iostream>
+
+NumberInput::NumberInput(int min, int max) {
+ std::cout << "Enter number [" << min << ", " << max << "]: ";
+ std::cin >> value;
+ if (value < min || max < value) {
+ throw "Number outside of range!";
+ }
+}
+
+int NumberInput::GetValue() {
+ return value;
+}
+
+int main() {
+ while(true) {
+ try {
+ NumberInput a(5, 10);
+ std::cout << a.GetValue() * 2 << std::endl;
+ break;
+ }
+ catch (const char* error) {
+ std::cout << error << std::endl;
+ }
+ }
+}