I am writing a code which the code asks the user for 3 inputs. one should be numeric and other two need to compared using strcmp(). How do i make it to ask for the input again if one of the conditions is false. The user needs to be asked again and again until he puts in the correct inputs

 Respuesta aceptada

Geoff Hayes
Geoff Hayes el 23 de Abr. de 2020

0 votos

karan - use a while loop to ask for input until some condition is satisfied. For example,
number = 0;
while true
number = input('Please enter a number between 1 and 42: ');
if number >= 1 && number <= 42
break;
end
end

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Productos

Preguntada:

el 23 de Abr. de 2020

Respondida:

el 23 de Abr. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by