i want to Write a user-defined function that calculate total marks, out of 100,The course should include homework, midterms, and final exam and i dont know why didint work

1 回表示 (過去 30 日間)
function[A]=Q2pro(sum(homework),sum(midterms),FinalExam)
G1 = homework;
G2 =midterms;
G3 =FinalExam;
Gall = G1+G2+G3;
if (95 >= Gall)
disp('A+')
elseif ( 90 >= Gall)
disp('A')
elseif ( 85 >= Gall)
disp('B+')
elseif ( 80 >= Gall)
disp('B')
elseif ( 75 >= Gall)
disp('C+')
elseif ( 70 >= Gall)
disp('C')
elseif ( 65 >= Gall)
disp('D+')
elseif ( 60 >= Gall)
disp('D')
else
disp('not found')
end
end

回答 (1 件)

Jan
Jan 2022 年 5 月 20 日
if (95 >= Gall)
Read this loud: "If 95 is greater than Gall".
No, you want the other way around:
if Gall >= 95
The header of the function should show a warning in the editor:
function[A]=Q2pro(sum(homework),sum(midterms),FinalExam)
% ^^^^ ^ ^^^^ ^
You canot use functions in the list of input arguments. I assume you mean:
function Q2pro(homework, midterms, FinalExam)
There is no output "A" also.

カテゴリ

Help Center および File ExchangeDebugging and Analysis についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by