Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

How can I use the break and continue to keep this loop from stopping all together. When the user enters the inputs it gives a message bu tthen it stops the program. I want it to let the user try new numbers after they get the wrong numbers message

2 vues (au cours des 30 derniers jours)
Carlos So
Carlos So le 19 Fév 2014
Clôturé : MATLAB Answer Bot le 20 Août 2021
temperature=menu('Temperature Scale','Kelvin','Fahrenheit','Centigrade','Rankine'); T1 = input(['Enter your T_C value',': \n']); T2 = input(['Enter your T_H value',': \n']);
if temperature == 1
T_C=T1;
T_H=T2;
end
if temperature == 2
T_C= (5/9)*(T1-32)+273;
T_H= (5/9)*(T2-32)+273;
end
if temperature == 3
T_C= T1+273;
T_H= T2+273;
end
if temperature == 4
T_C= (5/9)*(T1);
T_H= (5/9)*(T2);
end
if T_H>=T_C COP=(T_C/(T_H-T_C)) if COP >= 0 break COP=(T_C/(T_H-T_C)) fprintf('The coefficient of performance is %f \n',COP) else beep disp('Ensure that T_Cold is not greater than T_Hot and that T_Cold and T_Hot are equal or greater than zero when converted to Kelvin') end end if T_H>=T_C
h=50;
A=1;
Qdot=h*A*(T_C-T_H);
if COP>=0
Qdot=h*A*(T_C-T_H);
end
else
beep
disp('Ensure that T1 is not greater than T2')
end

Réponses (2)

mohammed
mohammed le 19 Fév 2014
Modifié(e) : mohammed le 19 Fév 2014
the Basic idea could be
Dear ivan
see an example
close all
clear all
clc
DisplayPlot = 6;
a = [1,2 ,3,4,5 ]; % put your all desired input
while ~ismember(DisplayPlot,a)
DisplayPlotx = inputdlg({'select the given input: '},'DisplayPlot',1,{'0'});
DisplayPlot = str2double(DisplayPlotx);
end
I think you can do it . Best of Luck..

Carlos So
Carlos So le 19 Fév 2014
I'm not sure how to incorporate the While loop. I tried it and it kept messing with my other code and it wouldn't even give me the error message.
  1 commentaire
mohammed
mohammed le 19 Fév 2014
Dear ivan
see an example
close all
clear all
clc
DisplayPlot = 6;
a = [1,2 ,3,4,5 ]; % put your all desired input
while ~ismember(DisplayPlot,a)
DisplayPlotx = inputdlg({'select the given input: '},'DisplayPlot',1,{'0'});
DisplayPlot = str2double(DisplayPlotx);
end
even you can and one if condition . this loop will runs unless and until the user put desired input. i hope it will help....
sorry for late i was busy with my dinner.

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by