can i use inequalities in 'if' statements?

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

This is not MATLAB code:
endif
Yeah it wasn't done on MATLAB. I used Octave

Sign in to comment.

Answers (1)

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.

Asked:

on 21 Mar 2019

Commented:

on 24 Mar 2019

Community Treasure Hunt

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

Start Hunting!