switch case not recognizing input

2 views (last 30 days)
Code:user_input=input('Enter the mineral name: ')
switch user_input
case magnetite
fprintf('Mineral:Magnetite \n Formula:Fe3O4 \n Percent Iron:72.4 \n Melting Point (Celcius):1597')
case Magnetite
fprintf('Mineral:Magnetite \n Formula:Fe3O4 \n Percent Iron:72.4 \n Melting Point (Celcius):1597')
case hematite
fprintf('Mineral:Hematite \n Formula:Fe2O3 \n Percent Iron:69.9 \n Melting Point (Celcius):1565')
case Hematite
fprintf('Mineral:Hematite \n Formula:Fe2O3 \n Percent Iron:69.9 \n Melting Point (Celcius):1565')
case Goethite
fprintf('Mineral:Goethite \n Formula:FeO(OH) \n Percent Iron:62.9 \n Melting Point (Celcius):350')
case goethite
fprintf('Mineral:Goethite \n Formula:FeO(OH) \n Percent Iron:62.9 \n Melting Point (Celcius):350')
case limonite
fprintf('Mineral:Limonite \n Formula:2(FeO(OH))*3(H2O) \n Percent Iron:55 \n Melting Point (Celcius):variable')
case Limonite
fprintf('Mineral:Limonite \n Formula:2(FeO(OH))*3(H2O) \n Percent Iron:55 \n Melting Point (Celcius):variable')
case Siderite
fprintf('Mineral:Siderite \n Formula:FeCO3 \n Percent Iron:48.2 \n Melting Point (Celcius):450')
case siderite
fprintf('Mineral:Siderite \n Formula:FeCO3 \n Percent Iron:48.2 \n Melting Point (Celcius):450')
otherwise
disp('Mineral not recognized')
end
Output:
Error using input
Unrecognized function or variable 'siderite'.
Error in HW6P2 (line 1)
user_input=input('Enter the mineral name: ')

Accepted Answer

KSSV
KSSV on 3 Aug 2022
user_input=input('Enter the mineral name: ') ;
switch user_input
case 'magnetite'
fprintf('Mineral:Magnetite \n Formula:Fe3O4 \n Percent Iron:72.4 \n Melting Point (Celcius):1597')
case 'Magnetite'
fprintf('Mineral:Magnetite \n Formula:Fe3O4 \n Percent Iron:72.4 \n Melting Point (Celcius):1597')
case 'hematite'
fprintf('Mineral:Hematite \n Formula:Fe2O3 \n Percent Iron:69.9 \n Melting Point (Celcius):1565')
case 'Hematite'
fprintf('Mineral:Hematite \n Formula:Fe2O3 \n Percent Iron:69.9 \n Melting Point (Celcius):1565')
case 'Goethite'
fprintf('Mineral:Goethite \n Formula:FeO(OH) \n Percent Iron:62.9 \n Melting Point (Celcius):350')
case 'goethite'
fprintf('Mineral:Goethite \n Formula:FeO(OH) \n Percent Iron:62.9 \n Melting Point (Celcius):350')
case 'limonite'
fprintf('Mineral:Limonite \n Formula:2(FeO(OH))*3(H2O) \n Percent Iron:55 \n Melting Point (Celcius):variable')
case 'Limonite'
fprintf('Mineral:Limonite \n Formula:2(FeO(OH))*3(H2O) \n Percent Iron:55 \n Melting Point (Celcius):variable')
case 'Siderite'
fprintf('Mineral:Siderite \n Formula:FeCO3 \n Percent Iron:48.2 \n Melting Point (Celcius):450')
case 'siderite'
fprintf('Mineral:Siderite \n Formula:FeCO3 \n Percent Iron:48.2 \n Melting Point (Celcius):450')
otherwise
disp('Mineral not recognized')
end
Enter you input like: 'siderite'
  4 Comments
Craig Johnson
Craig Johnson on 3 Aug 2022
thanks i forgot about that stipulation

Sign in to comment.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps 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!