MATLAB: Keep getting error message for making a script for checking the value of a number between 100&200

check a number between two valuesscripts

So I'm trying to write a script that will ask the user to input a number between 100 and 200, inclusive. The program will check the actual user input. If the user input is not between 100 and 200, the program will keep asking for the input until the user provides a correct one. Then the program will print out the number. I have most of it working but it keeps running an error message that says
>> checkinput Index exceeds array bounds.
Error in checkinput (line 4) input=input('Enter a number between 100 and 200:');
My code is below but I'm a little lost on where I messed up.
% code
%this script will check to make sure user input is bw 100 and 200
%and print the input
input=input('Enter a number between 100 and 200:');
% if loop execution
if(input>=100 && input<=200)
fprintf('Value of Number: %d\n', input);
else
fprintf('Error! Must enter a number between 100 and 200.\n');
end

Best Answer

Explanation: that bug is very simple: you named a variable input, which shadows the inbuilt input function.
The very first time your code evaluates this line:
input=input('Enter a number between 100 and 200:');
MATLAB calls the inbuilt input function and then you define a variable named input so that from now on any input call refers to your variable, not the inbuilt function. So the next time you try to call that line, input refers to your variable. MATLAB thinks that you are trying to index into your variable, but the indices are bigger than that variable has elements, thus the error.
Solution: rename your variable input to x, or anything else that is not the name of an inbuilt function. Always check if name is free before using it:
which input -all