hi iam creating a hotel reservation form and wanted to calculate total cost of stay by the nights stayed. it requires an arrival date and departure date but i want to add a validation so if the user inputs an incorrect format a message box displays asking them to try again. here is my code already had a bit of help with converting the timespan so once again any help would be amazing. the error is on the line that begins "dateDiff = aDate" and it says the variables aDate and dDate are unassigned thanks in advance:
String arrival, departure;
arrival = textBox1.Text;
departure = textBox2.Text;
DateTime aDate, dDate;
try
{
aDate = DateTime.ParseExact(arrival, "dd/mm/yyyy", null);
dDate = DateTime.ParseExact(departure, "dd/mm/yyyy", null);
return;
}
catch
{
MessageBox.Show("Invalid input format please enter in format DD/MM/YYYY");
}
TimeSpan dateDiff;
dateDiff = dDate.Subtract(aDate);
int nights = (int)dateDiff.TotalDays;
textBox3.Text = ("" + nights);
textBox5.Text = ("£" + (nights * 115));