I have many inputs and I want specific outputs depend on the user what he chose
조회 수: 1 (최근 30일)
이전 댓글 표시
clear,clc;
%asking the user to choose the category%
fprintf('1. food\n');
fprintf('2. Clothes\n');
fprintf('3. bevarages\n');
fprintf('4. others\n');
food_num=1;
while food_num<=1
code= input('Please Kindly Enter the code of your category : ');
if code>=5
disp('Please enter the code again');
continue;
end
food_num=2;
end
if code==1
fprintf('1. fruits\n');
fprintf('2. vegetables\n');
fprintf('3. Meat and sea food\n');
fprintf('4. wheat products\n');
fprintf('5. Oil\n');
fprintf('6. Processed food\n')
fruit_num=2;
while fruit_num<=2
x= input('Please Kindly Enter the code of your type of food : ');
if x>=7
disp('Please enter the code again');
continue;
end
fruit_num=3;
end
switch x
case 1
fprintf('1. banna\n');
fprintf('2. orange\n');
fruit_number=3;
while fruit_number<=3
y= input('Please Kindly Enter the code of your fruits : ');
if y>=3
disp ('enter the code again')
continue;
end
fruit_number=4;
end
if y==1
z= input('enter the amout of bannan in kg weekly');
n= z*5;
fprintf('ur consumption of banna is : %f ',n);
elseif y==2
m= input('enter the amout of orange in kg weekly');
f= m*5;
fprintf('ur consumption of orange is : %f ',f);
else y>=3;
disp('please entire the code agaian');
end
case 2
fprintf('1. cabbage\n');
fprintf('2. onions\n');
fprintf('3. peas\n');
fprintf('4. potatoes\n');
fprintf('5. carrot\n');
fprintf('6. tomatoes\n');
fprintf('7. cassava\n');
fprintf('8. mushroom\n');
fprintf('9. corn\n');
fprintf('10. broccoli\n');
fprintf('11. cucumber\n');
vegi_num=4;
while vegi_num<=4
V= input('please entre the code of the vegitiable');
if V>=12
disp ('enter the code again')
continue;
end
vegi_num=5;
end
if V==1
l=input('inter the amount of cabbage in kg');
q=l*0.35;
fprintf('ur consumption of cabbage is : %f ',q);
elseif V==2
w=input('inter the amount of onions in kg');
b=w*0.32;
fprintf('ur consumption of cabbage is : %f ',b);
elseif V==3
e=input('inter the amount of peas in kg');
s=e*0.9;
fprintf('ur consumption of peas is : %f ',s);
elseif V==4
j=input('inter the amount of potatoes in kg');
c=j*0.8;
fprintf('ur consumption of potatoes is : %f ',c);
elseif V==5
p=input('inter the amount of carrot in kg');
u=p*0.4;
fprintf('ur consumption of carrot is : %f ',u);
elseif V==6
eY=input('inter the amount of tomatoes in kg');
a=eY*1.4;
fprintf('ur consumption of tomatoes is : %f ',a);
elseif V==7
M=input('inter the amount of cassava in kg');
A=M*1;
fprintf('ur consumption of cassava is : %f ',A);
elseif V==8
N=input('inter the amount of mushroom in kg');
x=N*0.48;
fprintf('ur consumption of mushroom is : %f ',x);
elseif V==9
C=input('inter the amount of corn in kg');
c=C*1;
fprintf('ur consumption of corn is : %f ',c);
elseif V==10
Z=input('inter the amount of broccoli in kg');
z=Z*2;
fprintf('ur consumption of broccoli is : %f ',z);
elseif V==11
T=input('inter the amount of cucumber in kg');
t=T*1.37;
fprintf('ur consumption of cucumber is : %f ',t);
end
case 3
fprintf('1. beef\n');
fprintf('2. fish\n');
fprintf('3. lamb & mutton\n');
fprintf('4. pork\n');
fprintf('5. chicken\n');
fprintf('6. prawns\n');
fprintf('7. eggs\n');
Meat_num=1;
while Meat_num<=1
Meat_seefood =input('please entre the code of the meat and sea food');
if Meat_seefood>=8
disp ('enter the code again')
continue;
end
Meat_num=2;
end
if Meat_seefood==1
H=input('inter the amount of beef in kg');
h=H*60;
fprintf('ur consumption of beef is : %f ',h);
elseif Meat_seefood==2
F=input('inter the amount of fish in kg');
fa=F*5;
fprintf('ur consumption of fish is : %f ',fa);
elseif Meat_seefood==3
U=input('inter the amount of lamb & mutton in kg');
ua=U*24;
fprintf('ur consumption of lamb & mutton is : %f ',ua);
elseif Meat_seefood==4
P=input('inter the amount of pork in kg');
pa=P*7;
fprintf('ur consumption of pork is : %f ',pa);
elseif Meat_seefood==5
G=input('inter the amount of chicken in kg');
g=G*5.8;
fprintf('ur consumption of chicken is : %f ',g);
elseif Meat_seefood==6
XC=input('inter the amount of prawns in kg');
cx=XC*12;
fprintf('ur consumption of prawns is : %f ',cx);
elseif Meat_seefood==7
ES=input('inter the amount of eggs in kg');
es=ES*4.5;
fprintf('ur consumption of eggs is : %f ',es);
end
case 4
fprintf('1. rice\n');
fprintf('2. groundnut\n');
wheat_products=3;
while wheat_products<=3
Wheat_Products= input('Please Kindly Enter the code of your Products : ');
if Wheat_Products>=3
disp ('enter the code again')
continue;
end
wheat_products=4;
end
if Wheat_Products==1
XY=input('inter the amount of rice in kg');
xy=XY*4;
fprintf('ur consumption of rice is : %f ',xy);
elseif Wheat_Products==2
GR=input('inter the amount of groundnut in kg');
gr=GR*2.5;
fprintf('ur consumption of groundnut is : %f ',gr);
end
case 5
fprintf('1. Olive oil \n');
fprintf('2. palm oil \n');
fprintf('3. rapessed oil\n');
fprintf('4. sunflower oil\n');
oil_num=3;
while oil_num<=4
Oil= input('Please Kindly Enter the code of your Products');
if Oil>=5
disp ('enter the code again')
continue;
end
oil_num=5;
end
if Oil==1
QW=input('inter the amount of Olive oil in kg');
qw=QW*6;
fprintf('ur consumption of Olive oil is : %f ',qw);
elseif Oil==2
PO=input('inter the amount of palm oil in kg');
po=PO*8;
fprintf('ur consumption of palm oil is : %f ',po);
elseif Oil==3
RO=input('inter the amount of rapessed oil in kg');
ro=RO*3.09;
fprintf('ur consumption of rapessed oil is : %f ',ro);
elseif Oil==4
SO=input('inter the amount of sunflower oil in kg');
so=SO*4.2;
fprintf('ur consumption of sunflower oil is : %f ',so);
end
case 6
fprintf('1. Pizza \n');
fprintf('2. Baked Beans \n');
fprintf('3. Sausages\n');
fprintf('4. Dumplings\n');
fprintf('5. Chicken Pie\n');
fprintf('6. Liver& Bacon\n');
fprintf('7. Steak\n');
fprintf('8. Baked Potatoes\n');
processed_num=8;
while processed_num<=8
processed_food= input('Please Kindly Enter the code of your Products');
if processed_food>=9
disp('enter the code again');
continue;
end
processed_num=10;
end
if processed_food==1
PP=input('inter the amount of Pizza in kg');
pp=PP*4.4;
fprintf('ur consumption of Pizza is : %f ',pp);
elseif processed_food==2
BB=input('inter the amount of Baked Beans in kg');
bb=BB*1.5;
fprintf('ur consumption of Baked Beans is : %f ',bb);
elseif processed_food==3
SS=input('inter the amount of Sausages in kg');
ss=SS*4.6;
fprintf('ur consumption of Sausages is : %f ',ss);
elseif processed_food==4
DD=input('inter the amount of Dumplings in kg');
dd=DD*14;
fprintf('ur consumption of Dumplings is : %f ',dd);
elseif processed_food==5
CP=input('inter the amount of Chicken Pie in kg');
cp=CP*4.2;
fprintf('ur consumption of Chicken Pie is : %f ',cp);
elseif processed_food==6
LB=input('inter the amount of Liver& Bacon in kg');
lb=LB*12.5;
fprintf('ur consumption of Liver& Bacon is : %f ',lb);
elseif processed_food==7
eQ=input('inter the amount of Steak in kg');
EQ=eQ*11.3;
fprintf('ur consumption of Steak is : %f ',EQ);
elseif processed_food==8
BP=input('inter the amount of Baked Potatoes in kg');
bp=BP*2.2;
fprintf('ur consumption of Baked Potatoes is : %f ',bp);
end
end
end
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!