Website Summary Files Commits Branches @commit @diff @stats
path: root / Week11 / Exercise02 / main.cpp
diff options
context:
space:
mode:
Commit5e9cb4ddc811465731596d8ee684f3d8cd5a6aea (patch)
Author
 Syndamia <kamen@syndamia.com>
2026-05-02 16:05:06 +0300
Committer
 Syndamia <kamen@syndamia.com>
2026-05-02 16:05:06 +0300
Files33a9268d1136974d2ef138364dde508ba43b4a52 /Week11/Exercise02/main.cpp
oop-2025-solutions-main.tar
oop-2025-solutions-main.tar.gz
oop-2025-solutions-main.zip
Parent7546f0d0da487e16f0a8671c09a46e1cee2bc03a (diff)
feat(Week11): Add solutions HEAD main
1 files changed, 25 insertions, 0 deletions
-rw-r--r--Week11/Exercise02/main.cpp25
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 <cmath>
+#include <iostream>
+
+Option<double> trySqrt(double x) {
+ if (x < 0.0)
+ return Option<double>::None();
+ return Option<double>::Some(sqrt(x));
+}
+
+int main() {
+ double num;
+ std::cin >> num;
+
+ Option<double> numRoot = trySqrt(num);
+
+ if (numRoot.IsSome()) {
+ std::cout << numRoot.Unwrap() << std::endl;
+ }
+ else {
+ std::cout << "Couldn't find square root!" << std::endl;
+ }
+
+ return 0;
+}