Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using TestInput;
- /*
- from Lesson 6 of C# console programming tutorial series at following URL:
- http://williammillerservices.com/windows-c-console-programming/
- demonstrates calculating whole years that have elapsed since given date in the past
- GitHub gist -> https://gist.github.com/kyrathasoft/d00c2bdecd1a405d864f5be1789879f1
- Pastebin.com -> https://pastebin.com/jXC0B9EV
- */
- namespace MyAgePreditorNamespace
- {
- class MyAgePredictorClass
- {
- static void Main(string[] args)
- {
- //declare vars we'll need...
- string sData = String.Empty;
- DateTime dt;
- /* loop till valid date entered, or user indicates
- she wants to quit by entering letter Q */
- while (!Tester.IsDate(sData))
- {
- string msg = "Please enter your birthdate ";
- msg += "(mm/dd/yyyy), or \"Q\" to quit: ";
- Console.Write(msg);
- sData = Console.ReadLine().Trim();
- if (sData.ToLower() == "q") { Environment.Exit(0); }
- }
- dt = DateTime.Parse(sData);
- Console.WriteLine("You entered a valid date: {0}",
- dt.ToShortDateString());
- if (dt < DateTime.Now)
- {
- int age = Tester.GetDifferenceInYears(dt, DateTime.Now);
- if (age > 4)
- {
- Console.WriteLine("Your current age: {0}", age.ToString());
- age++;
- Console.Write("I predict you'll be {0} ", age.ToString());
- Console.WriteLine("years old a year from now...");
- }
- else
- {
- Console.Write("You're {0}, for crying out loud! ", age);
- Console.WriteLine("That's hardly old enough to be typing...");
- }
- }
- else
- {
- Console.Write("Uh... the birth date you entered ");
- Console.WriteLine("lies...like...in the future, dude.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement