I'm being asked to write a program to validate a date entered by a user. The date must be entered as three integer variables representing day, month and year. Output must state whether or not the date is valid.
Sounds simple enough... All I need to do is ask the user to input a day, Month and year. Then recall this and display it as a date. However I may want the user to enter the month first as this way I'll be able to work out how many days are in that month.
What I think I need to do is start with an array or 3 I need to get the program to remember how many days there are in each month so if the month is entered as February it wont accept anything greater than 29 is an input.
Before I start to evening look at Visual Studio, am I think anywhere along the right lines for this? Or is there another angle I can take to this?
Okay so I've been working on this and this is what I've got.
int monthentered = 0;
int dayentered = 0;
int year = 0000;
int [] month = new int [12];
int [] day = new int [31];
bool leap = false;
for (int x = 0; x <= 11; x++)
{
month[x] = x+1;
}
for (int x = 0; x <= 30; x++)
{
day[x] = x+1;
}
Console.WriteLine("Please enter a year...");
year = (Convert.ToInt16(Console.ReadLine()));
Console.WriteLine("{0}", year);
Console.WriteLine("Please enter a month...");
monthentered = (Convert.ToInt16(Console.ReadLine()));
Console.WriteLine("Please enter a day...");
dayentered = (Convert.ToInt16(Console.ReadLine()));
while (monthentered == 01 || 03 || 05 || 07 || 08 || 10 || 12)
{
while (dayentered == 31)
{
Console.WriteLine("There are only 30 days in this month please re-enter your day...");
dayentered = (Convert.ToInt16(Console.ReadLine()));
}
}
while (monthentered == 02)
{
while (dayentered > 28)
{
Console.WriteLine("There are only 28 days in this month please re-enter your day...");
dayentered = (Convert.ToInt16(Console.ReadLine()));
}
}
Console.WriteLine("{0}/{1}/{2}", dayentered, monthentered, year);
Console.ReadKey();
Issue with the while monthenter = bit. can someone provide me with help as to what I've done wrong?