Feedback on program please!!

Hello everyone!!
So I have been working on this program which ask to input dates as a sequence of three integers and checks to see if they are valid dates. the program should verify if the years are non-negative, months should be in the range 1-12, and days should be in the range from 1 to the number of days in the given month, and check for leap years. this is the code I have. If you guys can take a look at it and give me any feedback on it. I would really appreciate it. I have ran it varies times and it workds fine but if you find any problems with it I would really appreciate it if you point out anything wrong with. Thanks a lot!!


Last edited on
Your variable ifLeapYear is misnamed. Leap year is determined by the last part of the initization expression. isLeapDay would have been a better choice.

Similarly, ifNotALeapYear would be better described as isValidFebruaryDay or isFebruaryNonLeapDay.

I don't see any check for day==0

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
Last edited on
Thank you for your feedback. I'm a bit confused about the check for day. I thought that day <=30 would check for the months that have 30 days and day <=31 for the months that have 31 days. I thought that this section of my program checked for the dates part? I am just beginning with the C++ programming and your feedback would be great!

bool monthsWith31Days = ((month == 1 || month == 3 || month == 5 || month == 7
|| month == 8 || month == 10 || month == 12) && day <=31);
bool monthsWith30Days = ((month == 4 || month == 6 || month == 9 || month == 11) && day <=30);
I think Abstraction means that you are only checking if the date is less than or equal to 31 (or 30) days. You aren't checking if the date is greater than zero. So 3 0 2012 comes back as a valid date. I imagine a negative number would as well.
Thanks for your reply. How would i go about and doing the check for the day?
Would this work for checking the day?

1
2
3
4
5
 bool isFebruaryNonLeapDay = ( month == 2 && day > 0 && day <= 28 );

bool monthsWith31Days = (( month == 1 || month == 3  || month == 5 || month == 7 
							|| month == 8  || month == 10  || month == 12) && day > 0 && day <=31 );
bool monthsWith30Days = (( month == 4  || month == 6  || month == 9  || month == 11) && day > 0 && day <=30 );
Yes, that looks fine.
ok thank you for your feedback
Topic archived. No new replies allowed.