I am writing a code that allows a user to enter their name, and then check if the name starts with A,B or C and do someting. I am getting an error, please check my code below

1 view (last 30 days)
THEMBINKOSI Dlamini on 13 Apr 2022
Answered: Image Analyst on 13 Apr 2022

Answers (2)

Cris LaPierre
Cris LaPierre on 13 Apr 2022
Use the optional 2nd input to input to indicate the input is a string.
name = input('enter your name : ',"s")
The other option is to enter you input as a character array:
enter your name: 'ra'

Image Analyst
Image Analyst on 13 Apr 2022
Try using startsWith():
name = input('enter your name : ', 's')
if startsWith(name, 'A', 'IgnoreCase',true) || startsWith(name, 'B','IgnoreCase',true) || startsWith(name, 'C', 'IgnoreCase',true)
age = input('Enter your age : ');
% Do something.


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!