Skip to content

Instantly share code, notes, and snippets.

@Cellane
Created April 14, 2013 21:01
Show Gist options
  • Save Cellane/5384188 to your computer and use it in GitHub Desktop.
Save Cellane/5384188 to your computer and use it in GitHub Desktop.
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