%3Cp%20class%3D%22c3%22%3E%3Cspan%20class%3D%22c1%20c1%22%3EWrite%20a%20MATLAB%2
ID: 3552748 • Letter: #
Question
%3Cp%20class%3D%22c3%22%3E%3Cspan%20class%3D%22c1%20c1%22%3EWrite%20a%20MATLAB%20program%20which%0Aconverts%20a%20user-entered%20temperature%20value%20into%20Celsius%2C%20Fahrenheit%2C%0AKelvin%20and%20Rankine%20values.%20%20The%20user%20must%20input%20temperature%20in%0Aeither%20%E2%80%98C%E2%80%99%20or%20%E2%80%98F%E2%80%99.%26nbsp%3B%20If%20the%20input%20temperature%20is%20less%20than%20zero%0ACelsius%2C%20display%20the%20message%20%E2%80%98freezing%E2%80%99%3B%26nbsp%3B%20if%20above%2040%20C%20%E2%80%98very%0Ahot%E2%80%99%3B%20if%20above%20100%20C%20%E2%80%98boiling%E2%80%99%3B%26nbsp%3B%20if%20below%20zero%20Kelvin%20or%20zero%0ARankine%20display%20%E2%80%98impossible%E2%80%99.%26nbsp%3B%20If%20the%20user%20does%20not%20enter%0Aeither%20%E2%80%98C%E2%80%99%20or%20%E2%80%98F%E2%80%99%20with%20their%20temperature%20input%20the%20program%20should%0Aoutput%20a%20message%20indicating%20that%20Kelvin%20is%20assumed.%26nbsp%3B%20This%0Amight%20involve%20the%20use%20of%20a%20%E2%80%98logical%E2%80%99%20operator%20(and%2C%20or%20%2Cnot%3B%0A%26amp%3B%2C%7C%2C~)%20for%20example%3A%3C%2Fspan%3E%3Cbr%20class%3D%22c2%22%20%2F%3E%0A%3Cstrong%20class%3D%22c3%20c2%22%3Eif%3C%2Fstrong%3E%3Cstrong%20class%3D%0A%22c3%20c2%22%3E%26nbsp%3Bunits~%3D%3C%2Fstrong%3E%3Cstrong%20class%3D%0A%22c3%20c2%22%3E'C'%3C%2Fstrong%3E%3Cstrong%20class%3D%22c3%20c2%22%3E%26nbsp%3B%26amp%3B%20units%0A~%3D%26nbsp%3B%3C%2Fstrong%3E%3Cstrong%20class%3D%22c3%20c2%22%3E'F'%3C%2Fstrong%3E%3Cbr%20class%3D%0A%22c2%22%20%2F%3E%0A%3Cstrong%20class%3D%22c3%20c2%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%0Afprintf(%3C%2Fstrong%3E%3Cstrong%20class%3D%22c3%20c2%22%3E'you%20did%20not%20enter%20correct%0Aunits%2C%20Kelvin%20assumed%5Cn'%3C%2Fstrong%3E%3Cstrong%20class%3D%0A%22c3%20c2%22%3E)%3C%2Fstrong%3E%3Cbr%20class%3D%22c2%22%20%2F%3E%0A%3Cstrong%20class%3D%22c3%20c2%22%3Eend%3C%2Fstrong%3E%3C%2Fp%3E%0A%3Cp%20class%3D%22c3%22%3E%3Cspan%20class%3D%22c1%20c1%22%3E%26nbsp%3BRevise%20your%20C-F-K-R%0Atemperature%20conversion%20program%20to%20allow%20an%20indeterminate%20number%20of%0Arepetitions%20(via%20'while'%20structure.%20%26nbsp%3BThe%20user%20should%20be%20asked%0A'Do%20you%20wish%20to%20repeat%20this%20program'.%20)%20%26nbsp%3BIn%20addition%20to%20the%0Aoriginal%20program%20output%2C%20the%20program%20should%20determine%20and%20output%0Athe%20average%20temperature%20as%20well%20as%20the%20%26nbsp%3Bmaximum%20and%20minimum%0Atemperatures%20converted%3C%2Fspan%3E%3C%2Fp%3E%0AExplanation / Answer
sum=0;
min=0;
max=0;
flag=1;
count=0;
while flag==1
t=input('enter temperature ');
count=count+1;
p=input('enter the unit,either C or F for celcius or farenheit');
if p~='C' || p~= 'F'
disp('no unit entered.kelvin assumed.')
k=t;
c=k-273;
f=1.8*c+32;
r=0.8*c;
end
if p=='C'
c=t;
f=1.8*c+32;
r=0.8*c;
k=c+273;
else
f=t;
c=(5/9)*(f-32);
r=0.8*c;
k=c+273;
end
sum=sum+c;
if c>=max
max=c;
end
if c<min
min=c;
end
x1=['given temperature is ',num2str(c),' degree celcius.'];
x2=['given temperature is ',num2str(r),' degree rankin.'];
x3=['given temperature is ',num2str(f),' degree farenheit.'];
x4=['given temperature is ',num2str(k),' degree kelvin.'];
disp(x1)
disp(x2)
disp(x3)
disp(x4)
if c<=0
disp('freezing.')
else
if c>=40
disp('hot')
else
if c>=100
disp('boiling')
else
if k<0 || r<0
disp('imposiible.')
end
end
end
end
flag=input('do you want to continue? enter 1 for yes,0 for no');
end
x5=['maximum temperature is ',num2str(max),' degree celcius.'];
x6=['minimum temperature is ',num2str(min),'degree celcius'];
avg=sum/count;
x7=['averagetemperature is ',num2str(avg),'degree celcius'];
disp(x5)
disp(x6)
disp(x7)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.