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

조회 수: 3 (최근 30일)
adena0
adena0 2019년 1월 18일
편집: adena0 2019년 1월 18일
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