Created
April 14, 2013 21:01
-
-
Save Cellane/5384188 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace FifthTask | |
{ | |
class Program | |
{ | |
private static DateTime _dateOfBirth; | |
private static bool _parseSuccessful; | |
static void Main() | |
{ | |
ReadDateOfBirth(); | |
PrintCalculations(); | |
} | |
private static void ReadDateOfBirth() | |
{ | |
do | |
{ | |
try | |
{ | |
Console.Write("Please enter your birthdate: "); | |
_dateOfBirth = DateTime.Parse(Console.ReadLine()); | |
_parseSuccessful = true; | |
} | |
catch (FormatException) | |
{ | |
_parseSuccessful = false; | |
} | |
} while (_parseSuccessful == false); | |
} | |
private static void PrintCalculations() | |
{ | |
Console.WriteLine("Congratulations! You have been using oxygen on this planet for {0} days so far.", | |
(DateTime.Now.Date - _dateOfBirth.Date).Days); | |
Console.WriteLine( | |
_dateOfBirth.AddDays(1000) > DateTime.Now | |
? "You will celebrate your 1000th day alive on {0}." | |
: "You have celebrated your 1000th day alive on {0}.", | |
_dateOfBirth.AddDays(1000).ToShortDateString()); | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment