While loop to get correct user input

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

답변 (1개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2020년 11월 27일
편집: Sulaymon Eshkabilov 2020년 11월 27일

0 개 추천

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) ....

카테고리

도움말 센터File Exchange에서 Image Filtering and Enhancement에 대해 자세히 알아보기

태그

질문:

2020년 11월 27일

편집:

2020년 11월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by