MATLAB: Conditionals and character arrays to assign grade based on score

conditionals

How would I set up a statement to assign a letter grade based on an inputed score. eg. if score is between 90 and 100 then grade = a.
This is what I have so far:
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

Best Answer

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
Related Question