i have create a program that it will loop back if input y , but if user input other value, still will end the program . how can i restricted the value just y and n
2 views (last 30 days)
Show older comments
i=0;N='y';
while N=='y'
area=input('Please select area (kitchen, bathroom or storeroom):','s');
k='kitchen';
b='bathroom';
s='storeroom';
switch area
case 'kitchen'
N=input('\nDo you want to reselect area? yes/no \n Enter (y/n)= ','s');
case'bathroom'
case'storeroom'
otherwise
disp('Error is detected. Please select the area again!!!')
end
end
disp('finish')
0 Comments
Answers (1)
DGM
on 28 Jan 2022
This might do what you need.
selectarea = true;
while selectarea
area = input('Please select area (kitchen, bathroom or storeroom): ','s');
switch lower(area)
case 'kitchen'
disp('you selected kitchen')
case'bathroom'
disp('you selected bathroom')
case'storeroom'
disp('you selected storeroom')
otherwise
disp('Error is detected. Please select the area again!!!')
continue;
end
f = input('Do you want to reselect the area? (Y/N): ','s');
selectarea = ~isempty(f) && lower(f(1))=='y';
end
0 Comments
See Also
Categories
Find more on Time Series in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!