Switch function to output number of days in a month

7 visualizaciones (últimos 30 días)
GeoLandar
GeoLandar el 3 de Nov. de 2019
Comentada: GeoLandar el 3 de Nov. de 2019
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]);

Respuesta aceptada

Stephen23
Stephen23 el 3 de Nov. de 2019
Editada: Stephen23 el 3 de Nov. de 2019
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

Más respuestas (1)

Walter Roberson
Walter Roberson el 3 de Nov. de 2019
switch(lower(n))
case 'january'

Categorías

Más información sobre Calendar en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by