25. Is the following code correct as a data validation check? If not, how would you correct? (3) if (month < 1 || month
Posted: Sun May 15, 2022 8:10 am
25. Is the following code correct as a data validation check? If
not, how
would you correct? (3)
if (month < 1 || month > 12)
fprintf('Error--invalid month');
else
% Check to see if day is valid
switch (month)
case {1,3,5,7,8,10,12}
max_day = 31;
fprintf('case 1-10');
case {4,6,9,11}
max_day = 30;
fprintf('case 4-11');
case 2
max_day = 28 + leap_day;
fprintf('case 2');
end
not, how
would you correct? (3)
if (month < 1 || month > 12)
fprintf('Error--invalid month');
else
% Check to see if day is valid
switch (month)
case {1,3,5,7,8,10,12}
max_day = 31;
fprintf('case 1-10');
case {4,6,9,11}
max_day = 30;
fprintf('case 4-11');
case 2
max_day = 28 + leap_day;
fprintf('case 2');
end