for some reasons this code doesnt want to work, what i am doing wrong here please help
1 次查看(过去 30 天)
显示 更早的评论
% function returns two params saving and company contributed savings
function [saving,companySaving] = fileSal(sal)
if sal >= 100000
saving = 0.1*60000 + 0.08*40000;
companySaving = 0;
elseif sal >= 60000
saving = 0.1*60000 + 0.08*(sal - 60000);
companySaving = 0.1*30000 + 0.05*30000;
elseif sal >= 30000
saving = 0.1*sal;
companySaving = 0.1*30000 + 0.05*(sal - 30000);
else
saving = 0.1*sal;
companySaving = 0.1*sal;
end
end
% code ends here
0 个评论
采纳的回答
Kevin Holly
2022-10-29
What issues are you having with the code?
The function doesn't produce any errors for me. Are the answers unexpected?
[saving,companySaving] = fileSal(100000)
[saving,companySaving] = fileSal(59000)
[saving,companySaving] = fileSal(2134)
[saving,companySaving] = fileSal(1335)
function [saving,companySaving] = fileSal(sal)
if sal >= 100000
saving = 0.1*60000 + 0.08*40000;
companySaving = 0;
elseif sal >= 60000
saving = 0.1*60000 + 0.08*(sal - 60000);
companySaving = 0.1*30000 + 0.05*30000;
elseif sal >= 30000
saving = 0.1*sal;
companySaving = 0.1*30000 + 0.05*(sal - 30000);
else
saving = 0.1*sal;
companySaving = 0.1*sal;
end
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!