can i use inequalities in 'if' statements?

83 次查看(过去 30 天)
CO$MO
CO$MO 2019-3-21
评论: CO$MO 2019-3-24
income = input('Enter the value of your income:');
Ml= income*0.15;
if (6000< income <=20000)
incTax= 0.17*(income-6000)
elseif (20000< income <= 50000)
incTax= 2380 + 0.3*(income-20000)
elseif (50000< income <= 60000)
incTax= 11380 + 0.42*(income-50000)
else (income >60000)
incTax= 15580 + 0.47*(income-60000)
endif
totTax= Ml+incTax;
str1= ['Medicare levy: ' num2str(Ml) ''];
str2= ['Income Tax: ' num2str(incTax) ''];
str= ['Total Tax due: ' num2str(totTax) ''];
disp(str1);
disp(str2);
disp(str);
% it does not produce the expected answers

回答(1 个)

Geoff Hayes
Geoff Hayes 2019-3-21
Co$mo - use inequalities as
if 6000 < income && income <= 20000)
Repeat this for each of your conditions where you are checking to see if a variable is within an interval.

类别

Help CenterFile Exchange 中查找有关 Get Started with MuPAD 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by