Effacer les filtres
Effacer les filtres

simple elseif loop doesn't work

3 vues (au cours des 30 derniers jours)
MiauMiau
MiauMiau le 30 Jan 2013
hi!
This is my code:
T = input('enter a number: ')
if 0 < T < 100
h = T - 10
elseif T > 100
h = 0.45*T+900
end
But even in case I type in "110", the result would be "100", which is wrong and shows that the programm doesn't enter the elseif statement. Why?
Thanks

Réponse acceptée

Thorsten
Thorsten le 30 Jan 2013
Modifié(e) : Thorsten le 30 Jan 2013
The problem occurs because
0 < T < 100
is evaluated for T = 110 as
(0 < T) < 100
1 < 100
1
Use
0 < T && T < 100
  1 commentaire
MiauMiau
MiauMiau le 30 Jan 2013
perfect, thank you!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by