Azzera filtri
Azzera filtri

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

1 visualizzazione (ultimi 30 giorni)
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?

Risposta accettata

KSSV
KSSV il 18 Gen 2019
prompt = 'Enter a number:';
S = input(prompt) ;
if mod(S,2)
S = input(prompt) ;
end
  1 Commento
adena0
adena0 il 18 Gen 2019
Modificato: adena0 il 18 Gen 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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Prodotti


Release

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by