-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
144 lines (130 loc) · 4.96 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
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
using System;
using System.Collections.Generic;
using System.Globalization;
//Made by SeenKid
namespace Calculatrice
{
class Program
{
static void Main(string[] args)
{
decimal? resultatTotal = null;
string readlineOutput;
bool isAdd = false;
bool isSub = false;
bool isDiv = false;
bool isMult = false;
Console.WriteLine("Bonjour et bienvenue dans la calculatrice.");
Console.WriteLine("Pour utiliser a bon escient la calculatrice, suivez les commandes ci-dessous.");
Console.WriteLine("Made by SeenKid");
Console.WriteLine();
do
{
Console.Write("* : Multiplication\n");
Console.Write("/ : Division\n");
Console.Write("- : Soustraction\n");
Console.Write("+ : Addition\n");
Console.Write("Q : Quitter l'application\n");
Console.Write("R : Reset le chiffre du calcul\n");
Console.Write("C : Clear la console\n\nVotre choix > ");
string calc = Console.ReadLine();
switch (calc)
{
case "+":
{
isAdd = true;
break;
}
case "-":
{
isSub = true;
break;
}
case "*":
{
isMult = true;
break;
}
case "/":
{
isDiv = true;
break;
}
case "C":
Console.Clear();
continue;
case "Q":
return;
case "R":
resultatTotal = null;
Console.Clear();
continue;
default:
Console.WriteLine("Vous n'avez choisi aucun calcul. Veuillez choisir une valeur correspondante. (* / - + C Q)");
continue;
}
decimal? firstDecimal;
if (!resultatTotal.HasValue)
{
do
{
Console.WriteLine("Entrez le nombre 1 : ");
readlineOutput = Console.ReadLine();
firstDecimal = StringToDecimal(readlineOutput);
} while (firstDecimal is null);
}
else
{
firstDecimal = resultatTotal;
}
decimal? secondDecimal;
do
{
Console.WriteLine("Entrez le nombre 2 : ");
readlineOutput = Console.ReadLine();
secondDecimal = StringToDecimal(readlineOutput);
} while (secondDecimal is null);
if (isSub)
{
resultatTotal = firstDecimal.Value - secondDecimal.Value;
}
else if (isAdd)
{
resultatTotal = firstDecimal.Value + secondDecimal.Value;
}
else if (isDiv)
{
resultatTotal = firstDecimal.Value / secondDecimal.Value;
}
else if (isMult)
{
resultatTotal = firstDecimal.Value * secondDecimal.Value;
}
PrintResult(resultatTotal.Value);
isAdd = isSub = isDiv = isMult = false;
} while (true);
}
//Made by SeenKid
private static decimal? StringToDecimal(string inputString)
{
var numberFortmatSeparatedByComa = new CultureInfo("en-US").NumberFormat;
var numberFortmatSeparatedByDot = new CultureInfo("fr-CH").NumberFormat;
if (!decimal.TryParse(inputString, NumberStyles.Any, numberFortmatSeparatedByDot, out decimal result))
{
if (!decimal.TryParse(inputString, NumberStyles.Any, numberFortmatSeparatedByComa, out result))
{
return null;
}
}
return result;
}
private static void PrintResult(decimal result)
{
Console.WriteLine();
Console.WriteLine("======================");
Console.WriteLine("votre résultat est : " + result);
Console.WriteLine("======================");
Console.WriteLine();
}
}
}