Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MATLAB: Assign inRange with 1 if userWeight is greater than 100 and less than or

ID: 3873036 • Letter: M

Question

MATLAB:

Assign inRange with 1 if userWeight is greater than 100 and less than or equal to 200.

---------------------------------------------------------------------------

function inRange = CheckWeight(userWeight)
% userWeight: User weight in pounds
% Assign inRange with 1 is userWeight is greater than 100
% and less than or equal to 200
if (userWeight>100 | userWeight<=200)
inRange = 1 % 1 indicates user's weight is in range
else
inRange=0
end

----------------------------------------

I am still getting the wrong answers for the assessment. Please help. It is stating when CheckWeight(85) returns 1 but should be 0. Same with (100) and (245)

Thank you.

Explanation / Answer

Corrected code:

CheckWeight.m

function inRange = CheckWeight(userWeight)
% userWeight: User weight in pounds
% Assign inRange with 1 is userWeight is greater than 100
% and less than or equal to 200
if ((userWeight>100) & (userWeight<=200))
inRange = 1; % 1 indicates user's weight is in range
else
inRange=0;
end

end

Sample Tests:

Note that: You were using "OR" operator in if condition which is wrong, we should use and operator!