-
Notifications
You must be signed in to change notification settings - Fork 1
/
CalculateLogic.cs
61 lines (55 loc) · 1.9 KB
/
CalculateLogic.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
59
60
61
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Reflection.Emit;
using System.Text;
using System.Windows.Forms;
namespace CalculatorApp
{
static class CalculateLogic
{
static public string ChooseOperation(Operation op, string s1, string s2)
{
if (op == Operation.Add)
{
return Sum(s1, s2);
}
else if (op == Operation.Subtract)
{
return Sub(s1, s2);
}
else if (op == Operation.Multiply)
{
return Mult(s1, s2);
}
else
{
return Div(s1, s2);
}
}
static public string Sum(string s1, string s2)
{
double numb1 = double.Parse(s1, CultureInfo.InvariantCulture);
double numb2 = double.Parse(s2, CultureInfo.InvariantCulture);
return (numb2 + numb1).ToString(CultureInfo.InvariantCulture);
}
static public string Sub(string s1, string s2)
{
double numb1 = double.Parse(s1, CultureInfo.InvariantCulture);
double numb2 = double.Parse(s2, CultureInfo.InvariantCulture);
return (numb2 - numb1).ToString(CultureInfo.InvariantCulture);
}
static public string Mult(string s1, string s2)
{
double numb1 = double.Parse(s1, CultureInfo.InvariantCulture);
double numb2 = double.Parse(s2, CultureInfo.InvariantCulture);
return (numb2 * numb1).ToString(CultureInfo.InvariantCulture);
}
static public string Div(string s1, string s2)
{
double numb1 = double.Parse(s1, CultureInfo.InvariantCulture);
double numb2 = double.Parse(s2, CultureInfo.InvariantCulture);
return (numb2 / numb1).ToString(CultureInfo.InvariantCulture);
}
}
}