フィルターのクリア

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 Center および File ExchangeFeature Detection and Extraction についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by