make input positive mandatory

5 次查看(过去 30 天)
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....

请先登录,再进行评论。

采纳的回答

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