Advertisement
kyrathasoft

tnb

Jul 23rd, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.67 KB | None | 0 0
  1. using System;
  2. using TestInput;
  3. /*
  4. Part of Lesson 7 of C# console programming intro series at URL:
  5. http://williammillerservices.com/windows-c-console-programming/
  6. GitHub gist: https://gist.github.com/kyrathasoft/a4087f5f55f33634fc13932f65eabecf
  7. Pastebin.com: https://pastebin.com/4cNXLcvQ
  8. */
  9. namespace CalcDaysTillNextBirthday
  10. {
  11.     class DaysTillNextBirthday
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.             //declare vars we'll need...
  16.             string sData = String.Empty;
  17.             DateTime dt;
  18.  
  19.             //loop till valid date entered
  20.             while (!Tester.IsDateAndLiesInThePast(sData))
  21.             {
  22.                 string msg = "Please enter your birthdate ";
  23.                 msg += "(mm/dd/yyyy): ";
  24.                 Console.Write(msg);
  25.                 sData = Console.ReadLine().Trim();
  26.                 if (Tester.IsDate(sData))
  27.                 {
  28.                     DateTime dt2 = DateTime.Parse(sData);
  29.  
  30.                     if (dt2 > DateTime.Now)
  31.                     {
  32.                         Console.WriteLine("Uh, your birth date can't lie in the future...");
  33.                     }
  34.                 }
  35.             }
  36.  
  37.             /* The string entered by the user at the keyboard can be parsed
  38.             to a DateTime that lies in the past... */
  39.  
  40.             dt = DateTime.Parse(sData);
  41.  
  42.             /* Calculate days till next birthday and print that data to the
  43.             console for the user to view */
  44.  
  45.             int days = Tester.DaysTillNextBirthday(dt);
  46.             Console.Write("Number of whole (i.e., full 24-hour) days till ");
  47.             Console.WriteLine("your next birthday: {0}", days.ToString());
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement