While loop to get correct user input
1 回表示 (過去 30 日間)
古いコメントを表示
I need to get the correct input from the user, when the user enters the wrong input, it display an error for the while material line. Not sure what im doing wrong here.
material = input('Please enter Uranium, Vanadium, Zinc, or Zirconium: ', 's');
while material ~= 'Uranium' && material ~= 'uranium' && material ~= 'Vanadium' && material ~= 'vanadium' && material ~= 'Zinc' && material ~= 'zinc' && material ~= 'Zirconium' && material ~= 'zirconium'
material = input('ERROR! Please enter Uranium, Vanadium, Zinc, or Zirconium: ', 's');
end
0 件のコメント
回答 (1 件)
Sulaymon Eshkabilov
2020 年 11 月 27 日
編集済み: Sulaymon Eshkabilov
2020 年 11 月 27 日
Use this string comparison command instead of simple comparison in your IF condition: strncmpi(material, 'uran', 4) || strncmpi(material, 'Uran', 4) || strncmpi(material, 'Zinc', 4) ....
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!