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
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
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
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
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.
Rik
Rik 2022-3-25
deleted comment:
OP on 12 Feb 2021
I figured it out now! Thank you so much!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by