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 月 6 日
コメント済み: 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!