필터 지우기
필터 지우기

switch case not recognizing input

조회 수: 1 (최근 30일)
Craig Johnson
Craig Johnson 2022년 8월 3일
댓글: Craig Johnson 2022년 8월 3일
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: ')

채택된 답변

KSSV
KSSV 2022년 8월 3일
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
KSSV
KSSV 2022년 8월 3일
It is working fine...your input should be in apostrophes.
Craig Johnson
Craig Johnson 2022년 8월 3일
thanks i forgot about that stipulation

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Feature Detection and Extraction에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by