I am having some issues calculating grades using matlab.
显示 更早的评论
Hello, I am having some issues getting the program to correctly calculate grades. It works when the range of x is between 90 and 100, but anything below displays incorrectly. For the first part of the question, I cannot use elseif statements, only if. I feel that once I figure this part out, the second part where I use elseif statements will be much easier. Here is my code:
x = 80;
if x >=90;
grade = 'A';
if x <= 89, x >= 80;
grade = 'B';
if x <= 79, x >= 70;
grade = 'C';
if x <= 69, x >= 60;
grade = 'D';
if x < 60;
grade = 'F';
end;
end;
end;
end;
end;
disp(grade)
Any help would be very much appreciated!
Thanks, Nick
采纳的回答
更多回答(1 个)
Chad Greene
2015-10-15
Or more succinctly,
x = 80;
letters = {'F','D','C','B','A'};
disp(letters{min([ max([floor((x-50)/10) 0])+1 5])})
类别
在 帮助中心 和 File Exchange 中查找有关 Whos 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!