can i use inequalities in 'if' statements?
68 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Geoff Hayes
le 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.
Voir également
Catégories
En savoir plus sur Get Started with MuPAD dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!