フィルターのクリア

Judging input word based on first letter

2 ビュー (過去 30 日間)
Andrew Wiebe
Andrew Wiebe 2015 年 10 月 4 日
回答済み: Walter Roberson 2015 年 10 月 4 日
How would I write an m-file that asks a user to input a word and only returns a correct response if the word begins with "A","B","C".
x=input('Please input a single word surrounded by parentheses.')
case(first letter begins with A,B,C)
disp(Input word is correct.)
case(first letter does not begin with A,B,C)
disp(Input is incorrect. Please input a correct word.)
end
thanks!

回答 (1 件)

Walter Roberson
Walter Roberson 2015 年 10 月 4 日
Use the 's' option of input(). Subscript to get the first letter. switch() with case {'A', 'B', 'C'}
Question: what about 'a', 'b', 'c' ?
Watch out for the user pressing return without entering a word

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by