while loop adjust 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 in matlab

main.m
uservalue = input("Enter a value between 0 and 80: ");
while (uservalue < 0) || (uservalue > 80)
    if (uservalue > 80)
        uservalue = uservalue - 5;
    elseif (uservalue < 0)
        uservalue = uservalue + 10;
    end
    disp("Adjusted value: " + uservalue);
    uservalue = input("Enter a new value between 0 and 80: ");
end
disp("Final value: " + uservalue);
371 chars
12 lines

The above code will continually prompt the user to input a value between 0 and 80 until they comply. If the original user input value is greater than 80, the code will subtract 5 from it until it falls within the 0-80 range. If the original user input value is less than 0, the code will add 10 to it until it falls within the 0-80 range. The final value is then displayed.

gistlibby LogSnag