MATLAB Answers

adena0
0

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

Asked by adena0
on 18 Jan 2019
Latest activity Edited by adena0
on 18 Jan 2019
Accepted Answer by KSSV
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?

  0 Comments

Sign in to comment.

Products


Release

R2018a

1 Answer

Answer by KSSV
on 18 Jan 2019
 Accepted Answer

prompt = 'Enter a number:';
S = input(prompt) ;
if mod(S,2)
S = input(prompt) ;
end

  1 Comment

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

Sign in to comment.