필터 지우기
필터 지우기

help with for and while loop?

조회 수: 1 (최근 30일)
spang
spang 2012년 11월 5일
답변: Adithi 2022년 7월 14일
im trying to creat a script that will calculate that will calculate the amount of savings on a given starting salary over 30 years. rent increases $200 every 5 years and monthly wages inceases 2% every year. i get how to make the for loop calculate the total savings, but how do i account for the rent and wages increase? i tried using if statement but it didnt work. here is my code so far...
clear;clc
monthlyWageAfterTaxes = 2700; numberOfYears=30; rent=800; utilities=300; insurance=200 auto=250 food_misc=325; numberOfMonths=360
for j=1:numberOfMonths monthlySavings=(monthlyWageAfterTaxes-rent-utilities-insurance-auto-food_misc) yearlySavings=monthlySavings*12 totalSavings=yearlySavings*30
end

답변 (1개)

Adithi
Adithi 2022년 7월 14일
Hello,
I understand that you are trying to figure out how to increase the wage every year and rent every five years. Refer to code below to increase rent and wage.
CODE:
clear;
clc
monthlyWageAfterTaxes = 2700;
numberOfYears=30;
rent=800;
utilities=300;
insurance=200
auto=250
food_misc=325;
numberOfMonths=360;
for j=1:numberOfMonths
monthlySavings=(monthlyWageAfterTaxes-rent-utilities-insurance-auto-food_misc)
yearlySavings=monthlySavings*12
totalSavings=yearlySavings*30
disp(j)
if ~mod(j/12,1) == 1
monthlyWageAfterTaxes = 1.2*monthlyWageAfterTaxes;
disp("wage increased");
end
if ~mod(j/60,1) == 1
rent = rent + 200;
disp("rent increased")
end
end
Hope this helps!.

카테고리

Help CenterFile Exchange에서 Cartesian Coordinate System Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by