Another function that don't function

2 views (last 30 days)
Jacob Smith
Jacob Smith on 7 Mar 2021
Answered: Walter Roberson on 7 Mar 2021
I had some help getting to this point, but anyways here's the problem for the function we need. I can't seem to get it to give me a complete answer. If i mess with the indexs I can get it to where it'll give me more than one answer, but they'll mostly be zeros. Help,please.
  • Write a MATLAB function that takes the input of a list of scores and gives the output of the number of scores that are between 0 and 79.
function n = score(list)
Test the function for the following input lists:
  • List 1 of 30 scores: 31, 70, 92, 5, 47, 88, 81, 73, 51, 76, 80, 90, 55, 23, 43,98,36,87,22,61,19,69,26,82,89,99,71,59,49,64
  • List 2 of 5 scores: 35, 18, 99, 74, 85
Here's where I'm at
function n = score(list)
index = 1;
% looping through the array
for i = 1:numel(list)
% if the number is between 0 and 79 then putting it in array n
if list(i) >= 0 && list(i) < 80
n(index) = list(i);
index = 1;
end
end
end

Answers (1)

Walter Roberson
Walter Roberson on 7 Mar 2021
n(index) = list(i);
index = 1;
What benefit is there in resetting the index to 1 when it is already 1?
What benefit is there in storing the values when you are just asked to count them?

Tags

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!