I have to write a program that checks the date of an invoice to make sure that the date is correct. So far, the code is set up so that if the month entered is >= 1 or <= 12 the month is valid. If the month is > 12 or < 1, the month is automatically set to 0. The day is set up similarly, If the day >= 1 or <= 31, the day is valid. If not, the day = 0. What I need to do now is make the limit for days to be dependent on the month, so that a date like 04/31/2015 can't be valid. Furthermore, the day needs to be set to 0 when the month = 0. I was wondering what the most effective way to improve my code so I can make this happen might be? Do I need to implement the Gregorian Calendar in any way? Anyway, here is my code so far:
if((day <=31) && (day >= 1))
dayDue = day;
else
day = 0;
if((month >= 1) && (month <= 12))
monthDue = month;
else
month = 0;
if((year >= 2011) && (year <= 2017))
yearDue = year;
else
year = 0;