Advertisement
kyrathasoft

nya

Jul 21st, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.11 KB | None | 0 0
  1. using System;
  2. using TestInput;
  3. /*
  4. from Lesson 6 of C# console programming tutorial series at following URL:
  5. http://williammillerservices.com/windows-c-console-programming/
  6.  
  7. demonstrates calculating whole years that have elapsed since given date in the past
  8. GitHub gist -> https://gist.github.com/kyrathasoft/d00c2bdecd1a405d864f5be1789879f1
  9. Pastebin.com -> https://pastebin.com/jXC0B9EV
  10. */
  11. namespace MyAgePreditorNamespace
  12. {
  13.     class MyAgePredictorClass
  14.     {
  15.         static void Main(string[] args)
  16.         {
  17.             //declare vars we'll need...
  18.             string sData = String.Empty;
  19.             DateTime dt;
  20.  
  21.             /* loop till valid date entered, or user indicates
  22.             she wants to quit by entering letter Q */
  23.             while (!Tester.IsDate(sData))
  24.             {
  25.                 string msg = "Please enter your birthdate ";
  26.                 msg += "(mm/dd/yyyy), or \"Q\" to quit: ";
  27.                 Console.Write(msg);
  28.                 sData = Console.ReadLine().Trim();
  29.                 if (sData.ToLower() == "q") { Environment.Exit(0); }
  30.             }
  31.  
  32.             dt = DateTime.Parse(sData);
  33.             Console.WriteLine("You entered a valid date: {0}",
  34.                 dt.ToShortDateString());
  35.  
  36.             if (dt < DateTime.Now)
  37.             {
  38.                 int age = Tester.GetDifferenceInYears(dt, DateTime.Now);
  39.  
  40.                 if (age > 4)
  41.                 {
  42.                     Console.WriteLine("Your current age: {0}", age.ToString());
  43.                     age++;
  44.                     Console.Write("I predict you'll be {0} ", age.ToString());
  45.                     Console.WriteLine("years old a year from now...");
  46.                 }
  47.                 else
  48.                 {
  49.                     Console.Write("You're {0}, for crying out loud! ", age);
  50.                     Console.WriteLine("That's hardly old enough to be typing...");
  51.                 }
  52.             }
  53.             else
  54.             {
  55.                 Console.Write("Uh... the birth date you entered ");
  56.                 Console.WriteLine("lies...like...in the future, dude.");
  57.             }
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement