make input positive mandatory

조회 수: 5 (최근 30일)
Colby Jennings
Colby Jennings 2021년 3월 4일
댓글: Colby Jennings 2021년 3월 4일
so i am trying to make this code have the user enter a positive integer, and if it isnt positive, then it needs to ask them over and over again until a positive integer is inputted. then continue with the code, but my code is only asking like 3 times im new to coding and matlab, can anyone help me out?
  댓글 수: 2
Colby Jennings
Colby Jennings 2021년 3월 4일
update... i see why it is happening three times, back down to second input stays....
Colby Jennings
Colby Jennings 2021년 3월 4일
i cant figure ou loops lol

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

채택된 답변

David Hill
David Hill 2021년 3월 4일
while 1
a=input('Please input a postive integer');
if isequal(a,floor(a))&&a>0
break;
end
display('a is not a positive integer');
end

추가 답변 (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