How can teachers answer this question?

/Write a program which repeatedly reads numbers until the user enters "done". Once "done" is entered, print out the total, count, and average of the numbers. Use an array to store all the numbers. Example of execution: Enter a number: 4 Enter a number: 5 Enter a number: 9 Enter a number: done Total = 18, count = 3, average= 6

4 件のコメント

Emma Swaggy
Emma Swaggy 2017 年 5 月 22 日
Are you Mr. Everywhere? And did you close one my questions i asked?
Emma Swaggy
Emma Swaggy 2017 年 5 月 22 日
Iam wondering why some people here don't want to help other when they know how to do
Thomas Nguyen
Thomas Nguyen 2018 年 4 月 8 日
KSSV is right :v it's basically the same goddamn question :w ... Code:
function[] = someonesHW_2()
idx=1;
prompt='Enter a number: ';
while true
inp=input(prompt,'s');
if inp=="done"
break;
elseif isstring(inp)==1 && inp~="done"
disp('Invalid input!')
continue
else
a=str2double(inp);
A(idx)=a;
idx=idx+1;
end
end
Sum=sum(A(:));
Ave=Sum/(idx-1);
disp(['Total = ',num2str(Sum),'; count = ',num2str(idx),'; average = ',num2str(Ave)]);
end%someonesHW_2()

回答 (0 件)

この質問は閉じられています。

質問済み:

2017 年 5 月 22 日

コメント済み:

2018 年 4 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by