Effacer les filtres
Effacer les filtres

How do I use a while loop to keep asking for input of even numbers?

2 vues (au cours des 30 derniers jours)
adena0
adena0 le 18 Jan 2019
Modifié(e) : adena0 le 18 Jan 2019
How do I aks user to input an even number but if the number is odd or equal to 0, it should keep asking for input?

Réponse acceptée

KSSV
KSSV le 18 Jan 2019
prompt = 'Enter a number:';
S = input(prompt) ;
if mod(S,2)
S = input(prompt) ;
end
  1 commentaire
adena0
adena0 le 18 Jan 2019
Modifié(e) : adena0 le 18 Jan 2019
thanks but, this was my code originally and it failed after enteriing and odd number twice. i think a while loop needs to be used i just don't know how

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


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by