a little PIZZA menu using MATLAB
이전 댓글 표시
I want to write a little menu in MATLAB for a user who wants to order pizza using the ‘input’ function to ask for a few options. For example, I can start by asking whether the pizza should be vegetarian if 1 = yes, then I ask for different types of veggies, if 2 = no ask for different meat options etc.
So far I tried as follows using 'if/else if/else' loop: I created 4 menus: vegetrian(2 menus) and Nonvegetrian(2 menus), as follows, But, in some steps it doesn't work. Can someone help me pls?
a=input('Vegetrian: ');
a1=input('Mix Vegetable:');
a2=input('SAAG:')
b=input('Nonvegetrian: ');
b1=input('chicken PIZZA:');
b2=input('Cheese PIZZA:')
if a==1
disp(a1);
elseif a1==2
dip(b);
elseif b==1
disp(b1);
elseif b1==2
dip(b2);
else
disp('Not Available');
end
댓글 수: 1
the cyclist
2017년 1월 28일
Please be more specific when you say, "But, in some steps it doesn't work". Are you getting an error message? If so, post the complete message. Or are you just getting an unexpected result? If that's the case, the tell us the inputs that led to the unexpected result, and what you expected to get.
답변 (3개)
the cyclist
2017년 1월 28일
Is it because of the typo
dip(b)
instead of
disp(b)
(and similar error later)?
Image Analyst
2017년 1월 28일
Overlay complicated. Why not simply use menu() and get the number of the flavor they want:
choices = {'Vegetrian: ', 'Mix Vegetabl','SAA','Nonvegetrian','chicken PIZZA','Cheese PIZZA'}
buttonNumber = menu('What kind of pizza do you want?', choices)
message = sprintf('You chose %s pizza.', choices{buttonNumber});
uiwait(helpdlg(message));
댓글 수: 2
Sam John
2017년 1월 28일
Image Analyst
2017년 1월 28일
Don't use elseif. Just have a bunch of separate if's.
Jan
2017년 1월 28일
The order of command is not correct:
a = input('Vegetrian: ');
a1 = input('Mix Vegetable:');
if a == 1
disp(a1);
end
Now both questions appear in the command window, but most likely you want:
a = input('Vegetrian: ');
if a == 1
a1 = input('Mix Vegetable:');
...
else
b = input('Nonvegetrian: ');
...
end
...
카테고리
도움말 센터 및 File Exchange에서 Vector Volume Data에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!