Advertisement
coasterka

ExtractInfoFromUserID

Mar 11th, 2014
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.60 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ExtractInfoFromUserID
  4. {
  5.     class ExtractInfoFromUserID
  6.     {
  7.         static void Main()
  8.         {
  9.             Console.WriteLine("Enter your ID (ID must be a 10 digit number): ");
  10.             string id = Console.ReadLine();
  11.             //validate user id
  12.             if (id.Length != 10)
  13.             {
  14.                 Console.WriteLine("Invalid ID!");
  15.             }
  16.             else
  17.             {
  18.                 Console.WriteLine("Valid ID");
  19.             }
  20.             //define user gender
  21.             string gender = id.Substring(8, 1);
  22.             int genderChecked = int.Parse(gender);
  23.             if (genderChecked % 2 == 0)
  24.             {
  25.                 Console.WriteLine("Gender: Male");
  26.             }
  27.             else
  28.             {
  29.                 Console.WriteLine("Gender: Female");
  30.             }
  31.             //define user age
  32.             string yearOfBirth = id.Substring(0, 2);
  33.             int year = int.Parse(yearOfBirth);
  34.             string monthChecked = id.Substring(2, 2);
  35.             int monthResult = int.Parse(monthChecked);
  36.             if (monthResult >= 21 && monthResult <= 32)
  37.             {
  38.                 year += 1800;
  39.             }
  40.             else if (monthResult > +41 && monthResult < +52)
  41.             {
  42.                 year += 2000;
  43.             }
  44.             else
  45.             {
  46.                 year += 1900;
  47.             }
  48.             Console.WriteLine("Year of birth: " + year);
  49.             string dayOfBirth = id.Substring(4, 2);
  50.             string monthOfBirth = id.Substring(2, 2);
  51.             //days left till next birthday
  52.             int day = int.Parse(dayOfBirth);
  53.             int month = int.Parse(monthOfBirth);
  54.             int userAge = 0;
  55.             userAge = DateTime.Now.Year - year;
  56.             Console.WriteLine("User age: " + userAge);
  57.             //write user birthday on the console
  58.             if (year >= 2000)
  59.             {
  60.                 month = month - 40;
  61.             }
  62.             if (year <= 1900)
  63.             {
  64.                 month = month - 20;
  65.             }
  66.             Console.WriteLine("User birthday: {0}.{1}.{2}", dayOfBirth, month, year);
  67.             DateTime futureDate = new DateTime(DateTime.Now.Year, month, day);
  68.             Console.WriteLine("Next birthday: {0:dd/MM/yyyy}", futureDate);
  69.             DateTime currentDate = new DateTime();
  70.             currentDate = DateTime.Now;
  71.             TimeSpan days = futureDate.Date - currentDate.Date;
  72.             int daysLeft = (int)days.TotalDays;
  73.             Console.WriteLine("Days left till next user birthday: {0}", daysLeft);
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement