-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathProgram.cs
58 lines (53 loc) · 1.97 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
52
53
54
55
56
57
58
using System.Diagnostics;
using static Calculator.MathLib;
namespace Calculator
{
internal class Program
{
static void Main(string[] args)
{
while (true)
{
Console.WriteLine("***********INPUT*****************");
Console.Write("Enter the first operande : ");
float op1 = float.Parse(Console.ReadLine());
Console.WriteLine("First operande detected : " + op1);
Console.Write("Enter the operator : ");
char oper = char.Parse(Console.ReadLine());
Console.WriteLine("Operator detected : " + oper);
Console.Write("Enter the second operande : ");
float op2 = float.Parse(Console.ReadLine());
Console.WriteLine("Second operande detected : " + op2);
Console.WriteLine();
Console.Clear();
Console.WriteLine("**********RESULT*****************");
try
{
MathRequest mathRequest = new MathRequest(op1, oper, op2);
mathRequest.Result = Calculate(mathRequest);
Console.WriteLine(mathRequest.ToString());
}
catch (MathLib.BadOperatorException ex)
{
Console.WriteLine("This operator " + oper + " doesn't exist !");
}
}
}
private static float Calculate(MathRequest mathRequest)
{
switch (mathRequest.Ope())
{
case '+':
return MathLib.Add(mathRequest);
case '-':
return MathLib.Sub(mathRequest);
case '*':
return MathLib.Mul(mathRequest);
case '/':
return MathLib.Div(mathRequest);
default:
throw new BadOperatorException();
}
}
}
}