It says : Not a valid input. You must enter freshman, sophomore, junior, or senior. How can i fix it ?

1 回表示 (過去 30 日間)
Brain Adams
Brain Adams 2018 年 10 月 22 日
コメント済み: YT 2018 年 10 月 22 日
studentsYear = menu('Chose your year in school','freshman','sophomore','junior','senior');
switch(studentsYear)
case 'freshman'
final_day = 'Monday';
case 'sophomore'
final_day = 'Tuesday';
case 'junior'
final_day = 'Wednesday';
case 'senior'
final_day = 'Thursday';
otherwise
fprintf('Not a valid input.\nYou must enter freshman, sophomore, junior, or senior.\n');
final_day=0;
end
if ischar(final_day)
fprintf('Your final will be given on %s.\n', final_day);
end

回答 (1 件)

YT
YT 2018 年 10 月 22 日
Your variable studentsYear returns a value 1, 2, 3 or 4 as defined by the order in your menu. So you should use the integers 1, 2, 3 and 4:
studentsYear = menu('Chose your year in school','freshman','sophomore','junior','senior');
switch(studentsYear)
case 1 %freshman
final_day = 'Monday';
case 2 %sophomore
final_day = 'Tuesday';
case 3 %junior
final_day = 'Wednesday';
case 4 %senior
final_day = 'Thursday';
otherwise
fprintf('Not a valid input.\nYou must enter freshman, sophomore, junior, or senior.\n');
final_day=0;
end
if ischar(final_day)
fprintf('Your final will be given on %s.\n', final_day);
end
  2 件のコメント
Brain Adams
Brain Adams 2018 年 10 月 22 日
Firstly, thank you so much. I have one question. Should i write the integers when i am using the menu? It is necessary because i am using menu, right?
YT
YT 2018 年 10 月 22 日
I'm not sure if I understand your question, but you can leave the menu as it is now. You do not need to change the menu names into integer values in order for it to work.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangePerformance and Memory についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by