make input positive mandatory
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Colby Jennings
am 4 Mär. 2021
Kommentiert: Colby Jennings
am 4 Mär. 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 Kommentare
Akzeptierte Antwort
David Hill
am 4 Mär. 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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!