Algorithm with inputdlg command

조회 수: 6 (최근 30일)
Jimmy
Jimmy 2012년 11월 19일
¡Hello everyone!, I need your collaboration with this algorithm, this must be written on a script.
  • Make a menu that allows the following:
MAIN MENU
  1. Read the name and identification number (ID) of the user.
  2. Print the name and the user identification number (ID) on the screen.
  3. Indicate whether the user is over or under 30 years old.
  4. Exit.
Make use of the CASE structure for this menu and develop each option.
Thanks.
  댓글 수: 3
Jimmy
Jimmy 2012년 11월 19일
Sir, I appreciate all the help, because I don't even know how to start this.
Walter Roberson
Walter Roberson 2012년 11월 20일
Please edit this question to have a better title, as the current title has no information about what you are trying to do; your title could apply to most questions that are posted here.

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2012년 11월 19일
Hints:
  1. inputdlg()
  2. fprintf()
  3. "if" statement
  4. return
  댓글 수: 4
Image Analyst
Image Analyst 2012년 11월 19일
Was there something about this
prompt = {'Enter matrix size:','Enter colormap name:'};
dlg_title = 'Input for peaks function';
num_lines = 1;
def = {'20','hsv'};
answer = inputdlg(prompt,dlg_title,num_lines,def);
that's unusually difficult to adapt? Why can't you just say "Enter your name" instead of "Enter matrix size" and "Enter your age" instead of "Enter colormap name"? Did you try that? To get numbers instead of cells, you might do this:
theirAge = str2double(answer{2})
Jimmy
Jimmy 2012년 11월 22일
편집: Jimmy 2012년 11월 22일
This in my actual code and it works, thanks for the hints.
dlg_prompts = {'Username:','Age:'};
dlg_title = 'Menu';
dlg_defaults = {'',''};
opts.Resize = 'on'; % A structure
dlg_ans = inputdlg(dlg_prompts,dlg_title,1,dlg_defaults,opts);
if isempty(dlg_ans) % If I close the menu
h=warndlg('You just closed the menu.');
else
username = char(dlg_ans(1));
userage = str2double(dlg_ans(2));
switch logical(true)
case userage < 0 || isnan(userage)
abc=('and you are confused.');
case userage > 30
abc=('and is over 30.');
case userage < 30
abc=('and is under 30.');
otherwise
abc=('.');
end
M = sprintf('The user %s, is years old %d years(s) %s\n',username,userage,abc);
m=msgbox(M);
end
waitfor(m);

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Jan
Jan 2012년 11월 19일
Reading the "Getting Started" chapters of the documentation is a good point to start from. Then define the problem exactly. E.g. "read the name" could mean reading a handwritten name on a sheet of paper, reading from an USB stick or computer readable batch, from the keyboard of from a list on the hard disk.
The indication whether the user is over or under 30 years old, is not clear also: How do you want to decide this?
  댓글 수: 2
Jimmy
Jimmy 2012년 11월 19일
It's like "introduce your name, ID and age" on the fields, then print all of this on screen and the indication whether the user is over or under 30 years old is with the "if" statement and/or using "switch case", finally the program will show: "you're over 30 years old" or "you're under 30 years old".
Thanks for your time.
Jan
Jan 2012년 11월 20일
Sorry, James, this still demands for too much guessing. What is "on the fields"? Does "print on screen" mean a text in a figure or in the command line? How is the age indicated? Please try to be a clear as possible and consider, that we do not have the faintest idea of what you are wanting to achieve. The less we have to guess, the more efficient and likely is a helpful answer.
I assume, that this is a homework question.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by