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