positive numbers using while loop

hello, how do i make the user enter only positive number in an array using while loop to check positivity? thanks

 Risposta accettata

Jan
Jan il 13 Nov 2017
ready = false;
while ~ready
d = input('Please input a positive number: ');
ready = (d > 0);
end

1 Commento

L
L il 13 Nov 2017
When i tested this code, i wrote a matrix of 2 negative numbers and one postive but it accepted the matrix.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange

Richiesto:

L
L
il 13 Nov 2017

Commentato:

L
L
il 13 Nov 2017

Community Treasure Hunt

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

Start Hunting!

Translated by