Hi,
I am trying to make a program which formats the date for the user and verifies leapyears and checks for invalid dates.
Below i have worked out the code to calculate leap years. But how would i go about formating the date so for example:
If the user entered the date 25/12/2010 the output would be "25th December 2010".
I guess i need an array to store the months and the days in a month and the "st, nd, rd, th" suffix's to the days.?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Date_Calculator
{
class Program
{
static void Main(string[] args)
{
int day, month, year;
Boolean leapYear;
Console.WriteLine("Enter the day");
day = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the month");
month = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the year:");
year = Convert.ToInt32(Console.ReadLine());
if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0))
leapYear = true;
else
leapYear = false;
Console.WriteLine("The date {2} {3} {0} is a leap year: {1}.", year, leapYear, day, month);
Console.ReadLine();
}
}
}
Any help appreciated.