Effacer les filtres
Effacer les filtres

make input positive mandatory

5 vues (au cours des 30 derniers jours)
Colby Jennings
Colby Jennings le 4 Mar 2021
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 commentaires
Colby Jennings
Colby Jennings le 4 Mar 2021
update... i see why it is happening three times, back down to second input stays....
Colby Jennings
Colby Jennings le 4 Mar 2021
i cant figure ou loops lol

Connectez-vous pour commenter.

Réponse acceptée

David Hill
David Hill le 4 Mar 2021
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
  1 commentaire
Colby Jennings
Colby Jennings le 4 Mar 2021
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

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by