multiple loopings in a program
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
badrul hisham
il 9 Apr 2016
Commentato: badrul hisham
il 9 Apr 2016
Hi, i have a coding that requires user to input 2 numbers that are within a specific range.for example, for the first number:(please choose a number ranging from 1 to 7). If the user chose a number that is out of range, it will prompt for another number until the number chosen is within range.Then the program will proceed and ask for the second number:(please choose a number ranging from 15 to 20). Same as before, the number must be within range, otherwise it will just keep asking for a number. Can you please show me how to this?
Thank you
0 Commenti
Risposta accettata
Più risposte (1)
Walter Roberson
il 9 Apr 2016
Modificato: Walter Roberson
il 9 Apr 2016
while true
num = input('get on with the first number');
if numels(num) ~= 1 || num < 1 || num > 7
fprintf('Oh, you.. .you!\n');
else
break;
end
end
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!