coasterka

userID

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