blob: f734373464883d5cb2deb0a48e4c145e9069feca (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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;
}
|