Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Modify temperature conversion code so the user can convert as many temperatures

ID: 3632589 • Letter: M

Question

Modify temperature conversion code so the user can convert as many
temperatures as they wish and input capital or lower case temperature scales (i.e. c, C, f, F).

Here is my original code and and lost at the last part of my assignmnent about inputing as many temperatures as they wish step :-(

clc, clear;
% Group #4 Homework #10B
%A program that converts between farenheit, celcius, and kelvin.
T=input('Please input temperature value: ');
Initial_Temp_Type=input('Specify what temperature scale it is: ','s');
Final_Temp_Type=input('Sepcify what temperature to convert to: ','s');
if Initial_Temp_Type=='F'
if Final_Temp_Type=='C'
Final_T=(T-32)*5/9;
elseif Final_Temp_Type=='K'
Final_T=(T-32)*5/9+273;
end
end
if Initial_Temp_Type=='C'
if Final_Temp_Type=='F'
Final_T=(T+32)*9/5;
elseif Final_Temp_Type=='K'
Final_T=(T+32)*9/5+273;
end
end
if Initial_Temp_Type=='K'
if Final_Temp_Type=='F'
Final_T=(T)*9/5-459;
elseif Final_Temp_Type=='C'
Final_T=T-273;
end
end

fprintf('%.1f',Final_T);

Explanation / Answer

clc, clear; % Group #4 Homework #10B %A program that converts between farenheit, celcius, and kelvin. T=input('Please input temperature value: '); Initial_Temp_Type=input('Specify what temperature scale it is: ','s'); Final_Temp_Type=input('Sepcify what temperature to convert to: ','s'); if Initial_Temp_Type == 'f' Initial_Temp_Type = 'F'; elseif Initial_Temp_Type == 'c' Initial_Temp_Type = 'C'; elseif Initial_Temp_Type == 'k' Initial_Temp_Type = 'K'; end if Final_Temp_Type == 'c' Final_Temp_Type = 'C'; elseif Final_Temp_Type == 'f' Final_Temp_Type = 'F'; elseif Final_Temp_Type == 'k' Final_Temp_Type = 'K'; end for i = 1:numel(T) if Initial_Temp_Type=='F' if Final_Temp_Type=='C' Final_T(i)=(T(i)-32)*5/9; elseif Final_Temp_Type=='K' Final_T(i)=(T(i)-32)*5/9+273; end end if Initial_Temp_Type=='C' if Final_Temp_Type=='F' Final_T(i)=(T(i)+32)*9/5; elseif Final_Temp_Type=='K' Final_T(i)=(T(i)+32)*9/5+273; end end if Initial_Temp_Type=='K' if Final_Temp_Type=='F' Final_T(i)=(T(i))*9/5-459; elseif Final_Temp_Type=='C' Final_T(i)=T(i)-273; end end end fprintf('The temperatures are:'); for i = 1:numel(T) fprintf(' %.1f',Final_T(i)); if i == numel(T) break end fprintf(','); end fprintf('. ');

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote