I am new to all of this and cant figure out what it is I am doing wrong. I've been at this for sometime now and I've looked at a lot of reference material and still I have nothing working for me. What error have I made and how can it be fixed? I'm going braindead over here, please and thank you! I've underlined the current trouble spot.
function grade = lettergrade(score)
if score < 0 "OR" score > 100
grade = 'incorrect input';
elseif score <= 90 && score <= 100
grade = 'A';
elseif score >= 80 && score <= 90
grade = 'B';
elseif score >= 70 && score < 80
grade = 'C';
elseif score >= 60 && score < 70
grade = 'D';
elseif score < 60
grade = 'F';
end
Error: File: lettergrade.m Line: 2 Column: 19
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of
parentheses.

 採用された回答

Walter Roberson
Walter Roberson 2021 年 2 月 27 日

0 投票

if score < 0 || score > 100

5 件のコメント

Walter Roberson
Walter Roberson 2021 年 2 月 27 日
By the way, you do a lot of checking of both bounds, but you do not need to do that.
Suppose you were dealing with integers 1 to 9
if A>=7
that gets 7 8 9
elseif A>=5 && A<7
If you were starting with >= 5 then Yes, that would be 5 6 7 8 9 and in that case the < 7 would filter down to 5 6. But! The 7 8 9 was already consumed by the if before this, and only 1 to 6 are still "available" so you could just test >= 5
Jacob Smith
Jacob Smith 2021 年 2 月 27 日
I swear I tryed that already. It sort of worked, I'm not getting any error messages anymore, but my letter grades don't match up with my score inputs.
Walter Roberson
Walter Roberson 2021 年 2 月 27 日
Let me put it this way:
Switching to single boundaries like I described in my comment is also a good way to reduce the possibility that you have coded the pair of boundaries incorrectly.
Jacob Smith
Jacob Smith 2021 年 2 月 27 日
I think I'm smellin what you're cooking. Thanks for the help.
Jacob Smith
Jacob Smith 2021 年 2 月 27 日
Yep, everything is working as it should. Thanks!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Introduction to Installation and Licensing についてさらに検索

製品

リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by