can i use inequalities in 'if' statements?

71 views (last 30 days)
CO$MO
CO$MO on 21 Mar 2019
Commented: CO$MO on 24 Mar 2019
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
Stephen23
Stephen23 on 21 Mar 2019
This is not MATLAB code:
endif
CO$MO
CO$MO on 24 Mar 2019
Yeah it wasn't done on MATLAB. I used Octave

Sign in to comment.

Answers (1)

Geoff Hayes
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.

Community Treasure Hunt

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

Start Hunting!