フィルターのクリア

How to make sure user must login first then only they can proceed to next questions.

2 ビュー (過去 30 日間)
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

回答 (2 件)

Rohit
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).

Walter Roberson
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 ExchangeInteractive Control and Callbacks についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by