How can I inbuild choice several time?

조회 수: 1 (최근 30일)
ALEX TEY
ALEX TEY 2022년 1월 17일
답변: Prince Kumar 2022년 1월 20일
Hi, may I ask why I cant run this program?
I want to create a program which can give choice and inside the choice give choice to user again several time
Thank you
choice=menu('Choose Area','Kitchen','Bathroom',);
if choise==1
choice=menu('Choose Activity','Cooking','Cutting food');
if choice==1
choice=menu('Choose Action','Using fire to cook or boil water','w');
if choice==1
choice=menu('Choose Hazard','minor burn','major burn');
if choice==1
disp('Risk= 3')
disp('Recommended control measures=As quickly as possible soak the burn in cool water.')
else
choice==2
disp('Risk= 12')
disp('Reduce water temperature. Set the thermostat on your water heater to below 120 F (48.9 C).')
end
else choice==2
disp('Risk= 3')
disp('Recommended.')
end
else choice == 2
disp('Risk= 3')
disp('Recommended.')
end
else choice == 2
disp('Risk= ' )...
end
  댓글 수: 2
Naveen Somasundaram
Naveen Somasundaram 2022년 1월 17일
A note for you, Line 2 has a spell error "choise" instead of "choice".
ALEX TEY
ALEX TEY 2022년 1월 17일
thanks for reminding me

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

답변 (1개)

Prince Kumar
Prince Kumar 2022년 1월 20일
Hi,
For better clearity you can rename variables at each level of nesting as each of the conditional variable is names as "choice".
However the following piece of code is working fine.
choice=menu('Choose Area','Kitchen','Bathroom');
if choice==1
choice=menu('Choose Activity','Cooking','Cutting food');
if choice==1
choice=menu('Choose Action','Using fire to cook or boil water','w');
if choice==1
choice=menu('Choose Hazard','minor burn','major burn');
if choice==1
disp('Risk= 3')
disp('Recommended control measures=As quickly as possible soak the burn in cool water.');
else
choice==2
disp('Risk= 12')
disp('Reduce water temperature. Set the thermostat on your water heater to below 120 F (48.9 C).');
end
else choice==2
disp('Risk= 3');
disp('Recommended.');
end
else choice == 2
disp('Risk= 3');
disp('Recommended.');
end
else choice == 2
disp('Risk= ' );
end

카테고리

Help CenterFile Exchange에서 Food Sciences에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by