From 5e9cb4ddc811465731596d8ee684f3d8cd5a6aea Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 2 May 2026 16:05:06 +0300 Subject: feat(Week11): Add solutions --- Week11/Exercise02/main.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Week11/Exercise02/main.cpp (limited to 'Week11/Exercise02/main.cpp') diff --git a/Week11/Exercise02/main.cpp b/Week11/Exercise02/main.cpp new file mode 100644 index 0000000..f734373 --- /dev/null +++ b/Week11/Exercise02/main.cpp @@ -0,0 +1,25 @@ +#include "Option.hpp" +#include +#include + +Option trySqrt(double x) { + if (x < 0.0) + return Option::None(); + return Option::Some(sqrt(x)); +} + +int main() { + double num; + std::cin >> num; + + Option numRoot = trySqrt(num); + + if (numRoot.IsSome()) { + std::cout << numRoot.Unwrap() << std::endl; + } + else { + std::cout << "Couldn't find square root!" << std::endl; + } + + return 0; +} -- cgit v1.3.1-23-gd82d