-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
72 lines (56 loc) · 2.81 KB
/
Program.cs
File metadata and controls
72 lines (56 loc) · 2.81 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
using Microsoft.VisualBasic;
using System;
using System.Net.Cache;
namespace Lab1
{
class Program
{
static void Main(string[] args)
{
int yearOfBirth, monthOfBirth, dayOfBirth;
DateTime Now = DateTime.Now;
int ThisYear = Now.Year;
Console.WriteLine("Введите Ваше имя.");
string name = Console.ReadLine();
Console.WriteLine("Теперь введите год Вашего рождения. Но только из нашей эры.");
string enteredYear = Console.ReadLine();
while (!int.TryParse(enteredYear, out yearOfBirth) || yearOfBirth >= ThisYear)
{
Console.WriteLine("С такими числами мне не приходилось работать. Попробуйте снова");
enteredYear = Console.ReadLine();
}
Console.WriteLine("Теперь введите номер месяца от 1 до 12.");
string enteredMonth = (Console.ReadLine());
while (!int.TryParse(enteredMonth, out monthOfBirth) || monthOfBirth > 12)
{
Console.WriteLine("Пожалуйста, введите корректный номер месяца [1;12]");
enteredMonth = (Console.ReadLine());
}
int lastMonthDay = DateTime.DaysInMonth(yearOfBirth, monthOfBirth);
Console.WriteLine("Теперь введите номер дня, в который Вы родились");
string enteredDay = Console.ReadLine();
while (!int.TryParse(enteredDay, out dayOfBirth) || dayOfBirth > lastMonthDay)
{
Console.WriteLine("В уцказанном месяце нет дня с таким номером. Попробуйте снова.");
enteredDay = Console.ReadLine();
}
DateTime Birhday = new DateTime(yearOfBirth, monthOfBirth, dayOfBirth);
int Age = ThisYear - Birhday.Year;
if ( Now.Month <= Birhday.Month)
{
if (Now.Month == Birhday.Month)
{
if (Now.Day < Birhday.Day)
{
Age--;
}
}
else
{
Age--;
}
}
Console.WriteLine("Привет, " + name + ". Ваш возраст равен " + Age + " лет. Приятно познакомиться.");
}
}
}