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 comentario

the cyclist
the cyclist el 28 de En. de 2017
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.

Iniciar sesión para comentar.

Respuestas (3)

the cyclist
the cyclist el 28 de En. de 2017
Is it because of the typo
dip(b)
instead of
disp(b)
(and similar error later)?
Image Analyst
Image Analyst el 28 de En. de 2017
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 comentarios

Sam John
Sam John el 28 de En. de 2017
@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 el 28 de En. de 2017
Don't use elseif. Just have a bunch of separate if's.

Iniciar sesión para comentar.

Jan
Jan el 28 de En. de 2017
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
...

Etiquetas

Preguntada:

el 28 de En. de 2017

Respondida:

Jan
el 28 de En. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by