Info
This question is closed. Reopen it to edit or answer.
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 views (last 30 days)
Show older comments
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
0 Comments
Answers (2)
mohammed
on 19 Feb 2014
Edited: mohammed
on 19 Feb 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..
0 Comments
Carlos So
on 19 Feb 2014
1 Comment
mohammed
on 19 Feb 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.
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!