-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
290 lines (289 loc) · 12.5 KB
/
Program.cs
File metadata and controls
290 lines (289 loc) · 12.5 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp20
{
internal class Program
{
/// <summary>
/// Print "Press Any Key ..."
/// </summary>
static void PressAnyKey()
{
Console.WriteLine("Press Any key ... ");
Console.ReadKey();
}
/// <summary>
/// Print Your Text
/// </summary>
/// <param name="str">Your String to Print it</param>
/// <param name="myColor">Print your String with Your Color</param>
///
static void PrintMessage(string str, ConsoleColor myColor)
{
Console.ForegroundColor = myColor;
Console.WriteLine(str); ;
Console.ResetColor();
}
/// <summary>
/// Print Arrow Shape
/// </summary>
static void Arrow()
{
Console.ForegroundColor = ConsoleColor.Magenta;
Console.Write(" >>> ");
Console.ResetColor();
}
/// <summary>
/// Print Your Text
/// </summary>
/// <param name="t1">Your String</param>
/// <param name="MyColor">Your Color to Print Your Text</param>
static void Title(string t1, ConsoleColor MyColor)
{
Console.ForegroundColor = MyColor;
Console.WriteLine(t1);
Console.ResetColor();
}
/// <summary>
/// Print Your Text
/// </summary>
/// <param name="t1">Your First String To Print</param>
/// <param name="t2">Your Second String To Print</param>
/// <param name="MyColor">Your Color to Print Your Text</param>
static void Title(string t1, string t2, ConsoleColor MyColor)
{
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.Write(t1);
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.Write(" >>> ");
Console.ResetColor();
Console.ForegroundColor = MyColor;
Console.WriteLine(t2);
Console.ResetColor();
}
/// <summary>
/// Print Your Text
/// </summary>
/// <param name="t1">Your First String To Print</param>
/// <param name="t2">Your Second String To Print</param>
/// <param name="t3">Your Third String To Print</param>
/// <param name="MyColor">Your Color to Print Your Text</param>
static void Title(string t1, string t2, string t3, ConsoleColor MyColor)
{
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.Write(t1);
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.Write(" >>> ");
Console.ResetColor();
Console.ForegroundColor = MyColor;
Console.Write(t2);
Console.ResetColor();
Arrow();
Console.ForegroundColor = MyColor;
Console.WriteLine(t3);
Console.ResetColor();
}
/// <summary>
///
/// </summary>
/// <param name="t1">Your First String To Print</param>
/// <param name="t2">Your Second String To Print</param>
/// <param name="t3">Your Third String To Print</param>
/// <param name="t4">Your Forth String To Print</param>
/// <param name="MyColor">Your Color to Print Your Text</param>
static void Title(string t1, string t2, string t3, string t4, ConsoleColor MyColor)
{
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.Write(t1);
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.Write(" >>> ");
Console.ResetColor();
Console.ForegroundColor = MyColor;
Console.Write(t2);
Console.ResetColor();
Arrow();
Console.ForegroundColor = MyColor;
Console.Write(t3);
Console.ResetColor();
Arrow();
Console.ForegroundColor = MyColor;
Console.WriteLine(t4);
Console.ResetColor();
}
static void Separator(String Template, ConsoleColor w)
{
Console.ForegroundColor = w;
for (int i = 0; i < 113; i++)
{
Console.Write(Template);
}
Console.WriteLine();
Console.ResetColor();
}
static void Main(string[] args)
{
while (true)
{
Console.Clear();
Title("Calculate Console Application.", ConsoleColor.Yellow);
Separator("=", ConsoleColor.Yellow);
Console.WriteLine();
Console.WriteLine("1- Start Caculate");
Console.WriteLine("2- Exit ");
Console.WriteLine();
Console.Write("Please Enter Your choose : ");
int input = Convert.ToInt32(Console.ReadLine());
//input cheking
if (!(input == 1 || input == 2))
{
Console.Clear();
PrintMessage("Please Enter Correct Number of Menu item Number.", ConsoleColor.Red);
PressAnyKey();
continue;
}
//login Page
if (input == 1)
{
Calculator cal = new Calculator();
double input_First_Number;
double input_Second_Number;
string input_operator;
int indexOfCalculate = 0;
List<CalculateHistory> CalculateResult = new List<CalculateHistory>();
while (true)
{
indexOfCalculate++;
do
{
Console.Clear();
Title("Calculate Console Application.\t", ConsoleColor.Yellow);
Separator("=", ConsoleColor.Yellow);
Console.WriteLine();
Console.WriteLine("Calculate(" + indexOfCalculate.ToString() + ")" + " --->: ");
Console.WriteLine();
Console.Write("Please Enter First Number: ");
if (double.TryParse(Console.ReadLine(), out input_First_Number))
{
break;
}
else
{
Console.Clear();
PrintMessage("Please Enter Correct Format For Calculate Numbers.", ConsoleColor.Red);
PressAnyKey();
continue;
}
} while (true);
do
{
Console.Clear();
Title("Calculate Console Application.\t", ConsoleColor.Yellow);
Separator("=", ConsoleColor.Yellow);
Console.WriteLine();
Console.WriteLine("Calculate(" + indexOfCalculate.ToString() + ")" + " --->: " + input_First_Number);
Console.WriteLine();
Console.Write("Please Enter Your operator: ");
input_operator = Console.ReadLine();
if (input_operator.Equals("+") || input_operator.Equals("-") || input_operator.Equals("/") || input_operator.Equals("*"))
{
break;
}
else
{
Console.Clear();
PrintMessage("Please Enter Correct Format For Calculate Numbers. Please Choose between ----> *\t/\t+\tand\t-", ConsoleColor.Red);
PressAnyKey();
continue;
}
} while (true);
do
{
Console.Clear();
Title("Calculate Console Application.\tCalculate(" + indexOfCalculate.ToString() + ")", ConsoleColor.Yellow);
Separator("=", ConsoleColor.Yellow);
Console.WriteLine();
Console.WriteLine("Calculate(" + indexOfCalculate.ToString() + ")" + " --->: " + input_First_Number + " " + input_operator);
Console.WriteLine();
Console.Write("Please Enter Second Number: ");
string temp = Console.ReadLine();
if (input_operator == "/" && temp == "0")
{
Console.Clear();
PrintMessage("Cannot Divid By Zero. Please Enter Another Number.", ConsoleColor.Red);
PressAnyKey();
continue;
}
if (double.TryParse(temp, out input_Second_Number))
{
break;
}
else
{
Console.Clear();
PrintMessage("Please Enter Correct Format For Calculate Numbers.", ConsoleColor.Red);
PressAnyKey();
continue;
}
} while (true);
Console.Clear();
Title("Calculate Console Application.\t", ConsoleColor.Yellow);
Separator("=", ConsoleColor.Yellow);
Console.WriteLine();
try
{
string ResultOfCalculate = cal.Calcute(input_First_Number, input_operator, input_Second_Number).ToString();
Console.WriteLine("Calculate(" + indexOfCalculate.ToString() + ")" + " --->: " + input_First_Number + " " + input_operator + " " + input_Second_Number + " = " + ResultOfCalculate);
CalculateHistory temp = new CalculateHistory(indexOfCalculate, input_First_Number.ToString(), input_operator, input_Second_Number.ToString(), ResultOfCalculate);
CalculateResult.Add(temp);
}
catch (Exception ex)
{
Console.Clear();
PrintMessage(ex.Message, ConsoleColor.Red);
PressAnyKey();
continue;
}
Console.WriteLine();
PrintMessage("Continue? (y or n)", ConsoleColor.Cyan);
string Conculate = Console.ReadLine();
if (Conculate == "y")
{
continue;
}
else
{
Console.Clear();
Title("Calculate Console Application.\t", ConsoleColor.Yellow);
Separator("=", ConsoleColor.Yellow);
Console.WriteLine();
PrintMessage("Do you want to Show TotalCalculate History? (y or n)", ConsoleColor.Green);
string Conculate2 = Console.ReadLine();
if (Conculate2 == "y")
{
Console.Clear();
foreach (var item in CalculateResult)
{
Console.WriteLine(item.GetHistory());
}
Console.WriteLine();
PressAnyKey();
}
break;
}
}
}
//Exit
if (input == 2)
{
break;
}
}
}
}
}