using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FindingBirthday {
class Program {
static void Main(string[] args) {
// Create variables
int year = 0, month = 0, date = 0;
// Get the values
Console.WriteLine("How many years have passed?");
year = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("How many months have passed?");
month = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("How many days have passed?");
date = Convert.ToInt32(Console.ReadLine());
// Do the math and write it!
Console.WriteLine(
String.Format("Your birthday was on {0}",
DateTime.Now // Get current instance of time
.AddYears(-year) // Add years
.AddMonths(-month) // Add months
.AddDays(-date) // Add days
.ToString("MMMM dd, yyyy on dddd") // Format it
));
// Just for sake of pausing the Console
Console.Read();
}
}
}The above code requires three inputs. 1. Years, 2. Months and 3. Days that a person has lived on earth. Then it returns the date of birth of the user in a user-friendly way.
I hope this code snippet helps someone out. :)
