How to write a Questions that requires Yes or No asnwer

75 visualizaciones (últimos 30 días)
Michael Pipicelli
Michael Pipicelli el 5 de Sept. de 2019
Comentada: Rena Berman el 19 de Sept. de 2019
Hi,
I am trying to write a code where the user is ask a Yes or No questions and if they answer Yes the program conitunes if they answer No it ends
So far this is what i have
% Get building id
building_id = input('Enter the building ID >', 's');
wall = input('Enter a Wall (Y/N)>','s');
while wall == Y
continue
wall == N
quit
end
  6 comentarios
Walter Roberson
Walter Roberson el 6 de Sept. de 2019
menu() only permits the user to cancel or choose one of the provided choices, so it becomes unnecessary to loop back until the user chooses Y or N because they cannot choose anything else.
Rena Berman
Rena Berman el 19 de Sept. de 2019
(Answers Dev) Restored edit

Iniciar sesión para comentar.

Respuestas (3)

Walter Roberson
Walter Roberson el 5 de Sept. de 2019
Consider using questdlg() or menu()

Fangjun Jiang
Fangjun Jiang el 5 de Sept. de 2019
wall ='Y'
while wall == 'Y'
building_id = input('Enter the building ID >', 's');
wall = input('Enter a Wall (Y/N)>','s');
end
  3 comentarios
Fangjun Jiang
Fangjun Jiang el 5 de Sept. de 2019
In your code, there are syntax errors.
This code runs. You just need to hook up with the rest of your code.
Fangjun Jiang
Fangjun Jiang el 5 de Sept. de 2019
Maybe you need to consider using if-else statement, not the while loop.

Iniciar sesión para comentar.


Fangjun Jiang
Fangjun Jiang el 5 de Sept. de 2019
You need to wrap the code in a function so you can use "return" to terminate the program based on the input.
function test
wall = input('Enter a Wall (Y/N)>','s');
if wall=='N'
return;
end
% Get the wall id
wall_id = input('Wall ID>');

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by