Exemplo n.º 1
0
        internal static void Hypothenuse()
        {
            string s1 = Prompt("First leg:")
            , s2      = Prompt("Second leg:");

            var result = from a in Double.Parse(s1)
                         let aa = a * a
                                  from b in Double.Parse(s2)
                                  let bb = b * b
                                           select Math.Sqrt(aa + bb);

            WriteLine(result.Match(
                          () => "Please enter two valid, positive numbers",
                          (h) => $"The hypothenuse is {h}"));
        }
Exemplo n.º 2
0
        internal static void _main()
        {
            WriteLine("Enter a number, for which this program will calculate the square root:");
            var input = ReadLine();

            var result = from d in Double.Parse(input)
                         where 0 <= d
                         select Math.Sqrt(d);

            WriteLine(result.Match(
                          Some: r => $"sqrt({input}) = {r}",
                          None: () => "Please enter a valid, positive number"));

            ReadKey();
        }
Exemplo n.º 3
0
 static Validation <double> Validate(string s)
 => Double.Parse(s).Match(
     () => Error($"'{s}' is not a valid number"),
     d => Valid(d));