I am trying to create a function that asks a user to enter a capital letter A through J. if the letter is lowercase or from K-Z, I need to prompt the user to enter a valid letter. My code so far
function HumanInputFxn(Letter_Input)Good=0;%initilizes loop variable
while Good<1 Letter_Input=input('Enter capital letter from A to J:'); %allows user to enter a letter
if Letter_Input = num2cell('a':'z') || Letter_Input = num2cell('K':'Z') %a lower case letter or uppercase letter above J
fprintf('you entered %c \n please enter a capital, valid letter. \n',Letter_Input); else %if the input is a valid
fprintf('You have entered %c, a valid letter! You will now be prompted to enter a number.\n',Letter_Input) Good=1; %stops letter loop
endendend
I get errors the following errors:
Unrecognized function or variable 'Letter_Input'.
Error in HumanInputFxn(Letter_Input)
Incorrect use of '=' operator. To assign a value to a variable,
use '='. To compare values for equality, use '=='.
How can I properly define invalid inputs in my if statement? Why is Letter_Input not recognized? thanks
Best Answer