Request the user to input their seven digit KU ID that

3 visualizaciones (últimos 30 días)
Kyle Hillyer
Kyle Hillyer el 13 de Sept. de 2016
Editada: Stalin Samuel el 13 de Sept. de 2016
Request the user to input a seven digit ID number that starts with the number 78 (so it would be something like 78XXXXX, where X stands for any digit from 1-9, repeated or not). If their ID is anything other than 7 digits (6 or 8 or 10 digits or anything other than 7 digits) or if it does not start with 78 (say it starts with 25 or 98 or 00 or starts with anything other than 78), then print on the command window that their ID is invalid and then your program stops.
I am struggling with the first part of this prompt. I am not sure how to have the user input specific data, but have every thing else coded out. Any assistance would be helpful. Thanks!

Respuestas (2)

Adam
Adam el 13 de Sept. de 2016
All you need is a prompt that asks for that specific structure. Then they can type anything. You do the validation of what they typed afterwards and the print the appropriate message to screen. It doesn't even say that you need to ask them to try again to input the ID so it is easy in that aspect.
doc input
will help with asking the user for inputs. I always use a GUI myself, but these type of homework questions seem to expect just command line input.

Stalin Samuel
Stalin Samuel el 13 de Sept. de 2016
Editada: Stalin Samuel el 13 de Sept. de 2016
  1. make sure that you have entered 7 digits using
No=input('enter 7 digit KU ID'); % input
numel(num2str(No))%count the no of elements-output will be the number of digits
Using regular expression we can match the number whether the input no starts with 78 or not
m='78.....'
regexp(num2str(No),m,'match')

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by