Repeated user input for even numbers
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hariyali Ramesh
il 24 Gen 2019
Commentato: Hariyali Ramesh
il 24 Gen 2019
The code needs to keep asking for user input until an even number is inputted. I've got this code so far:
a = input('Input a value: ');
b = 2;
if rem(a,b) == 0
disp('Your value is even.')
else
a = input('Input a value of a');
end
but this only works twice when an odd number has been entered. How do I get it to keep asking for an input until an even number has been entered?
2 Commenti
Sarah Crimi
il 24 Gen 2019
%Create variable modvalue and use while loop to remain asking.
modvalue = 1;
while(modvalue~=0)
a = input('Input a value: ');
b = 2;
modvalue = rem(a,b)
end
disp('Your value is even.')
Risposta accettata
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Cell Arrays in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!