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
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
the cyclist 2017년 1월 28일

0 개 추천

Is it because of the typo
dip(b)
instead of
disp(b)
(and similar error later)?
Image Analyst
Image Analyst 2017년 1월 28일

0 개 추천

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
Sam John 2017년 1월 28일
@Image Analyst I am trying it based on input function and if/elseif/if loop.Do you have any idea based on this condition?Thanks
Image Analyst
Image Analyst 2017년 1월 28일
Don't use elseif. Just have a bunch of separate if's.

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

Jan
Jan 2017년 1월 28일

0 개 추천

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

질문:

2017년 1월 28일

답변:

Jan
2017년 1월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by