Program that sums as many numbers as user wants
4 views (last 30 days)
Show older comments
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 Comments
Walter Roberson
on 25 Mar 2022
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
on 25 Mar 2022
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.
Accepted Answer
James Tursa
on 12 Feb 2021
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 Comments
Walter Roberson
on 12 Feb 2021
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.
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!