From f3406754705e508f57768d3d0d8e457ff5b7620c Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 22 Apr 2024 15:43:49 +0300 Subject: [w8] Added exercise descriptions and solutions to ex 1-7 --- week08/Exercise6.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 week08/Exercise6.cpp (limited to 'week08/Exercise6.cpp') 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 + +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; + } + } +} -- cgit v1.2.3