Trying to run a user input factorial program.

Hello, I am trying to make a program that ask the user to select a factorial from 0 to 20 and produce an answer. But also display an error message if a number was picked that was less than 0 or greater than 20. I made this program but I'm not getting anywhere. Can anybody help me? Thank you.

답변 (1개)

Walter Roberson
Walter Roberson 2017년 2월 26일

0 개 추천

while true
x = input(....)
if x is in limits
break;
end
end
compute factorial

댓글 수: 2

while (x > 0)||(x > 20)
x = input('Enter a number to be factorialized from 1 to 20: ')
if (x < 0)||(x < 20)
break;
end
end
y = factorial(x)
Is this what it is supposed to look like? Thank you for helping me by the way.
"while true" is literal. It means to loop forever, until something inside the loop tells the loop to exit.
And notice I said "x is in limits". Think about what your "if" does for negative values.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

질문:

2017년 2월 26일

댓글:

2017년 2월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by