for some reasons this code doesnt want to work, what i am doing wrong here please help

1 Ansicht (letzte 30 Tage)
% 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

Akzeptierte Antwort

Kevin Holly
Kevin Holly am 29 Okt. 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 = 9200
companySaving = 0
[saving,companySaving] = fileSal(59000)
saving = 5900
companySaving = 4450
[saving,companySaving] = fileSal(2134)
saving = 213.4000
companySaving = 213.4000
[saving,companySaving] = fileSal(1335)
saving = 133.5000
companySaving = 133.5000
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

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by