switch case not recognizing input
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Craig Johnson
am 3 Aug. 2022
Kommentiert: Craig Johnson
am 3 Aug. 2022
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: ')
0 Kommentare
Akzeptierte Antwort
KSSV
am 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Biological and Health Sciences finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!