How to make sure user must login first then only they can proceed to next questions.
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Muhammad Ammar Fiqri Bin Johari Johari
el 6 de En. de 2023
Comentada: Muhammad Ammar Fiqri Bin Johari Johari
el 11 de En. de 2023
Hi i need help with the coding. I wan to make sure that users must login first before they can choose the next questions from the menu, that means user needs to enter their name and ID first then only after that they can proceed with other questions. Kindly need assistance, thank you.
%Define menu items
menuItems={'Login','Parts to print',,'Quit'};
%Display Menu
choose=DISPMENUSETTING(menuItems);
%Login
if choose==1
name=input('Enter your name:','s');
ID =input('Enter your ID:','s');
%Parts
elseif choose==2
name=input('What type of parts that you want to make?:','s');
%Quit
elseif choose==3
disp('Thank You')
break
0 comentarios
Respuestas (2)
Rohit
el 11 de En. de 2023
Hello,
In order to ask users to login before choosing from other menu options, you can separate the two. First ask the users to login (login screen) and only then show the other options of menu (menu screen).
One example of login screen logic in shown in the MATLAB Answers link below: https://www.mathworks.com/matlabcentral/answers/364791-how-can-i-prompt-the-user-for-their-name-and-store-it-while-returning-an-error-message-if-they-don?s_tid=answers_rc1-1_p1_Topic
0 comentarios
Walter Roberson
el 11 de En. de 2023
You can use the same logic, just restricted choices if the user has not already logged in.
This version of the code allows the user to log in again after they have already logged in -- for example if they wanted to switch to a different user.
%Define menu items
menuItems={'Login','Parts to print',,'Quit'};
have_logged_in = false;
while true
%Display Menu
thismenu = menuItems;
if ~have_logged_in; thismenu = thismenu(1); end
choose = DISPMENUSETTING(thismenu);
%Login
if choose==1
name=input('Enter your name:','s');
ID =input('Enter your ID:','s');
%Parts
have_logged_in = true;
elseif choose==2
name=input('What type of parts that you want to make?:','s');
%Quit
elseif choose==3
disp('Thank You')
break
end
end
1 comentario
Ver también
Categorías
Más información sobre Interactive Control and Callbacks 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!