フィルターのクリア

homework question, if statements

10 ビュー (過去 30 日間)
Shanna Resendez
Shanna Resendez 2015 年 6 月 20 日
コメント済み: Rik 2023 年 1 月 19 日
I am having trouble with this homework assignment
%1 Exercise
%Write a short code using IF construct
%that assigns a letter grade to a given numerical grade
%Do not use elseif construct, hint: nested if constructs may be useful
%95 < grade A
%86 < grade B <= 95
%76 < grade C <= 86
%66 < grade D <= 76
%0 < grade F <= 66
I have tried some n basic thing just to see if I can change the grade to a letter value, but I am having trouble. Here is an example.
grade = 97;
if(grade >= 95)
disp('A')
end

採用された回答

Walter Roberson
Walter Roberson 2015 年 6 月 20 日
編集済み: Walter Roberson 2015 年 6 月 20 日
if(grade >= 95)
disp('A')
end
is fine as far as it goes, but it does not assign the result to anything.
if grade >= 95
gradeletter = 'A';
end
But you should be checking whether 95 exactly is 'A' or 'B'
  1 件のコメント
Cris LaPierre
Cris LaPierre 2020 年 3 月 26 日
You can learn more about if statements in 10 minutes in MATLAB Onramp (chapter 12). It's free, self-paced, and interactive.

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

その他の回答 (1 件)

Adel Litim
Adel Litim 2023 年 1 月 19 日
clear;clc;
m=input('tell us how many student there are ? ');
for n=1:m
x=input(['tell us about the ',num2str(n),' student mark ? ']);
if x>95
disp('the grade is : A')
elseif x<95 & x>86
disp('the grade is : B')
elseif x<86 & x>76
disp('the grade is : C')
elseif x<76 & x>66
disp('the grade is : D')
elseif x<66 & x>0
disp('the grade is : F')
end
end
  1 件のコメント
Rik
Rik 2023 年 1 月 19 日
Why did you post this answer? What does it teach? You're more than welcome to start answering questions, but why post a solution to a homework question without any explanation?

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

カテゴリ

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