Info
此问题已关闭。 请重新打开它进行编辑或回答。
Write a Matlab code to add numbers until the user enters zero using while loop?
1 次查看(过去 30 天)
显示 更早的评论
just give me simple code plss
1 个评论
James Tursa
2022-2-1
What have you done so far? What specific problems are you having with your code?
回答(2 个)
Walter Roberson
2022-2-1
There is no simple code for that. Your code needs to take into account these possibilities:
- the user enters no input (just presses return)
- the user enters a vector of numeric values, none of which is 0
- the user enters a vector of numeric values, one of which is 0 -- not necessarily the last of them
- the user enters a character vector or string or cell array or other non-numeric value
- the user enters negative 0
- the user enters different data types. For example if the user enters -3 +1 uint8(1) 0 then what result is to be expected ?
0 个评论
Image Analyst
2022-2-1
编辑:Image Analyst
2022-2-1
Hint:
theSum = 0
while something
thisNumber = input(..........)
% code
theSum = theSum + ..............
end
You should be able to figure it out. If you can't go over this before replying:
and this:
0 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!