Program that sums as many numbers as user wants
12 次查看(过去 30 天)
显示 更早的评论
I need to write a program that displays the sum of user-provided numbers. The user should be able to provide as many numbers as they like, and when they are done providing numbers, the sum of those numbers needs to be displayed. I am super confused on this so please help! Thanks
5 个评论
Walter Roberson
2022-3-25
In some jurisdictions you have the legal right to ask that certain publicly identifiable information about you not be publicly available. Your ability to change your username and remove profile information about your interests satisfies that legal right.
However, when you posted your Question, you agreed to the Terms and Conditions of the website... which gives Mathworks the right to retain the content .
Rik
2022-3-25
You not only changed your profile picture and username (and perhaps also removed other information from your profile), but you also edit away your question. I had to manually reverse that and now you're suggesting you had every right to do so, just because you wanted to keep private information private. That is the problem.
采纳的回答
James Tursa
2021-2-12
An outline of the code could be:
total = 0;
while( true )
% insert code here to get a number from the user
% insert code here to see if the number is 0. If it is 0, then break out of the loop
% insert code here to add the number to total
end
% insert code here to display the total
3 个评论
Walter Roberson
2021-2-12
A modified version of Jame's outline, that permits 0 as an input:
total = 0;
while( true )
% insert code here to get a number from the user
% insert code here to see if the number is empty. If it is empty then break out of the loop
% insert code here to add the number to total
end
% insert code here to display the total
That is, when you use input() if the user just presses return, then MATLAB will receive the empty value into the variable.
更多回答(0 个)
另请参阅
类别
在 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!