Switch function to output number of days in a month

4 次查看(过去 30 天)
I am trying to use switch to output number of days for each month, however I am having issues with my input, Please advice.
here is my code:
n = input('Enter the month name: ');
switch n
case January
Days = '31';
otherwise
disp('Invalid month name');
return;
end
disp(['Days ', Days]);

采纳的回答

Stephen23
Stephen23 2019-11-3
编辑:Stephen23 2019-11-3
Actually you need to use the optional 's' argument for input, otherwise your code will throw an error:
n = input('Enter the month name: ','s');
switch lower(n)
...
end

更多回答(1 个)

Walter Roberson
Walter Roberson 2019-11-3
switch(lower(n))
case 'january'

类别

Help CenterFile Exchange 中查找有关 Calendar 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by