-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
51 lines (44 loc) · 1.42 KB
/
Program.cs
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SharpLab1
{
class Program
{
static bool TryInputVariable(string name, out double result)
{
Console.Write("Input {0}: ", name);
return double.TryParse(Console.ReadLine(), out result);
}
static void Main(string[] args)
{
while (true)
{
double a = 0;
double b = 0;
double c = 0;
bool parsingResult = false;
while (parsingResult = !TryInputVariable("a", out a)) ;
while (parsingResult = !TryInputVariable("b", out b)) ;
while (parsingResult = !TryInputVariable("c", out c)) ;
var result = SquareRootFinder.Calculate(a, b, c);
if (result.Roots == 1)
{
Console.WriteLine("X is {0}", result.X1);
}
else if(result.Roots == 2)
{
Console.WriteLine("X1 is {0}", result.X1);
Console.WriteLine("X2 is {0}", result.X2);
}
else if(result is ComplexSquareRootResult)
{
Console.WriteLine("No real roots found.");
}
Console.ReadKey(true);
}
}
}
}