can i use inequalities in 'if' statements?
71 views (last 30 days)
Show older comments
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
2 Comments
Answers (1)
Geoff Hayes
on 21 Mar 2019
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.
See Also
Categories
Find more on Get Started with MuPAD 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!