While loop with branching Write a while loop that adjusts userValue while userValue is less than 0 or greater than 80. If userValue is greater than 80, then subtract 5 from userValue. If userValue is less than 0, then add 10 to userValue. Function Save Reset MATLAB DocumentationOpens in new tab function userValue = AdjustValue(userValue) % Write a while loop that adjusts a userValue while userValue is less than 0 % or greater than 80 userValue = 0; % If the userValue is greater than 80, then subtract 5 from userValue % If the user value is less than 0, then add 10 to userValue end 1 2 3 4 5 6 7 8 9 10 Code to call your function Reset AdjustValue(-6) 1 Run Function

Respuesta :

Explanation:

The function AdjustValue has one input argument userValue.

Then we have implemented a while loop with conditions userValue is less than 0 or userValue is greater than 80 while any of the two conditions is satisfied the program will will continue.

Then we have used if else statement to adjust the userValue. If userValue is greater than 80 then subtract 5 from the userValue otherwise add 10 to the userValue.

Then we tested the function with AdjustValue(-6) and AdjustValue(90) and it returned the correct results.

Matlab Code:

function userValue = AdjustValue(userValue)  

while userValue < 0 || userValue > 80

if (userValue > 80)  

userValue = userValue - 5;  

break

else  

userValue = userValue + 10;  

break

end

end

Output:

>> AdjustValue(-6)

ans =

    4

>> AdjustValue(90)

ans =

   85

Ver imagen nafeesahmed

Answer:

function userValue = AdjustValue(userValue)

   while(userValue < 0 | userValue > 80)

       if (userValue > 80)

           userValue = userValue - 5

       elseif (userValue < 0)

           userValue = userValue + 10

       else

       end

    end

end

Explanation:

See other answer for a more in depth explanation. This is a modified form of the code. In opposition to the other answer, using "break" is not needed. Your homework will accept the answer without breaks.