Write a function called holiday that takes two input arguments called month and day; both are scalar integers representing a month (1-12) and a day (1-31). You do not need to check that the input is valid. The function returns a logical true if the s
Show older comments
function [v] = holiday(day,month)
a=[1,1];
b=[4,7];
c=[25,12];
d=[31,12];
A= [day,month]
if A == a | A == b | A == c |A == d
v= true
else
v=false
end
here i'm getting an error with input(7,4) . any idea why? the format for the code being(day,month) is adhered to.
Answers (5)
Hi,
Your condtion is A = [4,7] --> you tried [7,4]:
function [v] = holiday(day,month)
a=[1,1];
b=[4,7];
c=[25,12];
d=[31,12];
A = [day,month]
if A == a | A == b | A == c |A == d
v= true;
else
v=false;
end
v
check for x = holiday(4,7):
x = holiday(4,7)
v =
logical
1
x =
logical
1
check for y = holiday(7,4):
y = holiday(7,4)
v =
logical
0
y =
logical
0
Best regards
Stephan
1 Comment
Heirleking
on 29 Jul 2018
I have the same error,
Arrah Calvin
on 30 Jul 2018
Edited: Stephen23
on 30 Jul 2018
Here is my take on the problem. I've tested it, and it works. I don't know why your function doesn't work while it looks like it should.
function [v] = holiday(month,day)
a=[1,1];
b=[7,4];
c=[12,25];
d=[12,31];
A = [month,day];
if A == a
v=true;
elseif A == b
v=true;
elseif A == c
v=true;
elseif A == d
v=true;
else
v=false;
end
Duddela Sai Prashanth
on 23 Sep 2018
%Simplest one - Tested
function value = holiday(month,day)
if month == 1 && day == 1
value = true;
elseif month == 7 && day == 4
value = true;
elseif month == 12 && (day == 25 || day == 31)
value = true;
else
value = false;
end
Akshatha Gangappa
on 17 Oct 2018
0 votes
function [v] = holiday(m,d) if (( m==1 && d ==1) (m==7 && d ==4) (m==12 && d ==25)||(m ==12 && d== 31)) v = true; else v = false; end end
muhammad usman
on 5 Apr 2020
0 votes
function H = holiday(month,day);
if (month == 1 && day == 1) || (month == 7 && day ==4) || (month == 12 && day == 25) || (month == 12 && day == 31);
H = true;
else fprintf(' go to work\n '); H = false;
end
Categories
Find more on Calendar in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!