Trying to run a user input factorial program.
2 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
Walter Roberson
2017-2-26
while true
x = input(....)
if x is in limits
break;
end
end
compute factorial
2 个评论
Walter Roberson
2017-2-26
"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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!