-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoutils.cs
More file actions
61 lines (50 loc) · 1.61 KB
/
Copy pathoutils.cs
File metadata and controls
61 lines (50 loc) · 1.61 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
using System;
using System.Collections.Generic;
using System.Text;
namespace SentinelSyncV1
{
static class outils
{
public static int AskNPositiveNumberNotNull(string question)
{
return AskNumberBetween(question, 1, int.MaxValue, "ERROR : the number must be positive and not null");
}
public static int AskNumberBetween(string question, int min, int max, string messageErreurPersonnalise = null)
{
int nombre = AskNumber(question);
if (nombre >= min && nombre <= max)
{
return nombre;
}
if (messageErreurPersonnalise == null)
{
Console.WriteLine($"the number must be between {min} and {max}");
}
else
{
Console.WriteLine(messageErreurPersonnalise);
}
Console.WriteLine();
return AskNumberBetween(question, min, max, messageErreurPersonnalise);
}
public static int AskNumber(string question)
{
Console.Write(question);
int reponse = 0;
while (true)
{
try
{
reponse = int.Parse(Console.ReadLine());
return reponse;
}
catch
{
Console.WriteLine("ERROR : you must enter a number");
Console.WriteLine();
Console.Write(question);
}
}
}
}
}