Switch Case with Strings Help

22 visualizaciones (últimos 30 días)
Andrew
Andrew el 20 de Nov. de 2013
Comentada: Andrew el 20 de Nov. de 2013
Hello. I am trying to make a program that allows me to input different strings and displays the correct statement based on the string.
This is my code
Planet= input('Planet:');
switch lower(Planet)
case {'mercury','venus','earth','mars'}
disp('This is a Inner Planet')
case {'jupiter','saturn','uranus','neptune'}
disp('This is a Outer Planet')
otherwise
disp('No such planet exists.')
end
And the error i get is
>> switchcase
Planet:Earth
Error using input
Undefined function or variable 'Earth'.
Error in switchcase (line 1)
Planet= input('Planet:');
How do I correctly program this? Thanks!

Respuesta aceptada

Walter Roberson
Walter Roberson el 20 de Nov. de 2013
Planet= input('Planet:', 's');

Más respuestas (0)

Categorías

Más información sobre Earth and Planetary Science en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by