Program that sums as many numbers as user wants

조회 수: 4 (최근 30일)
Matthew Worker
Matthew Worker 2021년 2월 11일
댓글: Rik 2022년 3월 25일
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