Im trying make calender that is valid troughout, and its not working? febuary only has 29 0r 28 days and when I put in 30 for days for month 2, it should not allow me to do that, but instead it says there are 30 days in February. Month and the year are working perfectly fine??? help please ?why this function is not working???
int getdaysInMonth( int theMonth, int year){
int days(0);
while ( days < 1 || days > 31 ) {
if (theMonth == 2)
days = daysInFebruary(year);
else if (theMonth == 9 || theMonth == 4 || theMonth == 6 || theMonth == 11)
days = 30;
else
days = 31;
cout << "Enter a day in a month ( integer between 1....31)" ;
cin >> days;
}
return days;
}
int getdaysInMonth( int theMonth, int year){
int days(0);
while ( days < 1 || days > 31 ) {
if (theMonth == 2)
days = daysInFebruary(year);
elseif (theMonth == 9 || theMonth == 4 || theMonth == 6 || theMonth == 11)
days = 30;
else
days = 31;
cout << "Enter a day in a month ( integer between 1....31)" ;
cin >> days;
}
return days;
}
Second, the reason it's not working is because you set 'days' to the maximum number for that month, but then you reset it when you do cin >> days; on line 11. You should probably cin>> a different integer and check that it is not bigger than days. Cheers!