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

1 次查看(过去 30 天)
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?

采纳的回答

KSSV
KSSV 2019-1-18
prompt = 'Enter a number:';
S = input(prompt) ;
if mod(S,2)
S = input(prompt) ;
end
  1 个评论
adena0
adena0 2019-1-18
编辑:adena0 2019-1-18
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by