Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using TestInput;
- /*
- Part of Lesson 7 of C# console programming intro series at URL:
- http://williammillerservices.com/windows-c-console-programming/
- GitHub gist: https://gist.github.com/kyrathasoft/a4087f5f55f33634fc13932f65eabecf
- Pastebin.com: https://pastebin.com/4cNXLcvQ
- */
- namespace CalcDaysTillNextBirthday
- {
- class DaysTillNextBirthday
- {
- static void Main(string[] args)
- {
- //declare vars we'll need...
- string sData = String.Empty;
- DateTime dt;
- //loop till valid date entered
- while (!Tester.IsDateAndLiesInThePast(sData))
- {
- string msg = "Please enter your birthdate ";
- msg += "(mm/dd/yyyy): ";
- Console.Write(msg);
- sData = Console.ReadLine().Trim();
- if (Tester.IsDate(sData))
- {
- DateTime dt2 = DateTime.Parse(sData);
- if (dt2 > DateTime.Now)
- {
- Console.WriteLine("Uh, your birth date can't lie in the future...");
- }
- }
- }
- /* The string entered by the user at the keyboard can be parsed
- to a DateTime that lies in the past... */
- dt = DateTime.Parse(sData);
- /* Calculate days till next birthday and print that data to the
- console for the user to view */
- int days = Tester.DaysTillNextBirthday(dt);
- Console.Write("Number of whole (i.e., full 24-hour) days till ");
- Console.WriteLine("your next birthday: {0}", days.ToString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement