z = ''; while ~strcmp(z,' C to F') z = input(...) if strcmp(...) Convert... else Complain z = '' end end
How to make a repeat process for a statement in a while loop when condition is not met?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Quan Seah
le 16 Avr 2018
Modifié(e) : Walter Roberson
le 17 Avr 2018
Right now I am stuck as to how do I return z to asking for the conversion method if the 'C to F' is not entered correctly or nothing is entered. Help please.
clear,clc
x =[];
while isempty(x)
x = input('Make a choice(imperial or metric): ','s');
if strcmp(x,'imperial')
y = input('Please enter a value: ');
z = input('Conversion method (C to F): ','s');
if strcmp(z,'C to F')
convert(x,y,z)
end
elseif strcmp(x,'metric')
y = input('Please enter a value: ');
z = input('Conversion method (C to F): ','s');
else
x =[];
disp('Please make sure the spelling are correct!')
end
end
0 commentaires
Réponse acceptée
Walter Roberson
le 16 Avr 2018
Modifié(e) : Walter Roberson
le 17 Avr 2018
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!