conditionals and character arrays to assign grade based on score

조회 수: 5 (최근 30일)
I W
I W 2020년 11월 15일
편집: Walter Roberson 2021년 12월 17일
function grade = assignGrade(score)
%Enter the commands for your function here.
if (score >= 90) && (score <= 100)
grade = 'A'
end
This is my code to call my function:
score = 75;
grade = assignGrade(score)
assignGrade(91)=grade
none of this works but I have included it to show you what I have tried

채택된 답변

Walter Roberson
Walter Roberson 2020년 11월 15일
score = 75;
grade = assignGrade(score);
fprintf('The grade for score %d was %s\n', score, grade);
The grade for score 75 was undefined
function grade = assignGrade(score)
%Enter the commands for your function here.
if (score >= 90) && (score <= 100)
grade = 'A';
else
grade = 'undefined';
end
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Language Fundamentals에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by