aboutsummaryrefslogtreecommitdiff
path: root/week08/Exercise6.cpp
diff options
context:
space:
mode:
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;
+ }
+ }
+}