for some reasons this code doesnt want to work, what i am doing wrong here please help
1 view (last 30 days)
Show older comments
% 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 Comments
Accepted Answer
Kevin Holly
on 29 Oct 2022
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
More Answers (0)
See Also
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!