In: Computer Science
I need to ask a user what numbers they want to enter. They can enter as many as they like. Then inside I need to use conditionals to determine if the numbers are <=20, <=323 && > 30, >200. I can't figure out how to let the user enter as many inputs as they want. I know I need to use a loop to check each number entered and determine if it is small middle or greater but I can't figure that out. I want to display at the end each value they have entered and next to that say if it is greater small or middle. Here is what I got so far. THIS IS USING MATLAB
function num = wells(orval)
orval = input('Enter numbers: ');
for i = length(orval)
if i <= 20
disp('small')
elseif i <= 323 & i > 30
disp('middle')
elseif i > 200
disp('greater')
end
end
Answer
Here is your matlab code. I created below code based on the above information. So any doubt please comment i am here to helpy you. Any updation needed please comment.
Here is your matlab code
function wells() //removed orval parameter because we ask user inside the function
while(1) //infinite while loop user can enter infintite time until he enter -1.
orval = input('Enter numbers: ');
if orval==-1
break
end
if orval <= 20
disp('small')
else if orval <= 323 & orval > 30
disp('middle')
else if orval > 324 //you said 200, that never execute , so i used above 323 for greater
disp('greater')
end
end
end
end
end
output
Any doubt please comment, i am here to help you. The code is only based on the question you have given. Any updation please comment
Thanks in advance