How to make sure user must login first then only they can proceed to next questions.
2 次查看(过去 30 天)
显示 更早的评论
评论: Muhammad Ammar Fiqri Bin Johari Johari
2023-1-11
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 个评论
回答(2 个)
Rohit
2023-1-11
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 个评论
Walter Roberson
2023-1-11
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!