for some reasons this code doesnt want to work, what i am doing wrong here please help
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
ahmed
am 29 Okt. 2022
Kommentiert: ahmed
am 29 Okt. 2022
% 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 Kommentare
Akzeptierte Antwort
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,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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Whos finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!