simple elseif loop doesn't work

조회 수: 12 (최근 30일)
MiauMiau
MiauMiau 2013년 1월 30일
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

채택된 답변

Thorsten
Thorsten 2013년 1월 30일
편집: Thorsten 2013년 1월 30일
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
MiauMiau
MiauMiau 2013년 1월 30일
perfect, thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by