Problem1 Write an m-file that does C and F temperature conversions. Display a me
ID: 1767145 • Letter: P
Question
Problem1 Write an m-file that does C and F temperature conversions. Display a menu like the following to the user (doesn't have to be an exact match) Homework 7 Problem 1 Temperature Conversion Calculator Enter your choice from the options below: 1C->F Celsius to Fahrenheit 2. F-C Fahrenheit to Celsius Other choice: Exit Enter choice Use an if-elseif-else statement to do the temperature conversion and display the result to the user to two decimal places Example: Enter Celsius temperature: 23.0 Temperature F is: 73.40 Conversion: TempF (TempC*1.8)+32.0 TempC (TempF 32.0)/1.8 Note: If you ever forget the conversion equation, you can derive it quickly by remembering that the AT between the freezing point of water and the boiling point of water is 100'C and 180'F212F 32 F), so a AT of 1.8'F is equivalent to a AT of 1.0'C. The freezing point of water is 0 C or 32 F Problem 2. Using the same m-file as for Problem 1, do the same except use a switch-case statement instead of an if-elseif-else statement. Tip: After getting Problem 1 to work, much of the input/output code and math code can be copied to Problem 2.Explanation / Answer
SOLUTION TO PROBLEM 1:
MATLAB CODE:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
n=input('press 1 for Celcius to Fahrenheight and 2 for Fahrenheit to Celcius conversion:');
if n==1
TempC=input('Enter Temperature in Celcius:');
TempF=(TempC*1.8)+32;
disp('Temprature in Fahrenheit is:');
disp(TempF);
elseif n==2
TempF=input('Enter Temperature in Fahrenheit:');
TempC=(TempF-32)/1.8;
disp('Temprature in Celcius is:');
disp(TempC);
else
break;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SAMPLE RUN:
press 1 for Celcius to Fahrenheight and 2 for Fahrenheit to Celcius conversion:1
Enter Temperature in Celcius:100
Temprature in Fahrenheit is:
212
SOLUTION TO PROBLEM 2:
MATLAB CODE:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
n=input('press 1 for Celcius to Fahrenheight and 2 for Fahrenheit to Celcius conversion:');
switch n
case 1
TempC=input('Enter Temperature in Celcius:');
TempF=(TempC*1.8)+32;
disp('Temprature in Fahrenheit is:');
disp(TempF);
case 2
TempF=input('Enter Temperature in Fahrenheit:');
TempC=(TempF-32)/1.8;
disp('Temprature in Celcius is:');
disp(TempC);
otherwise
break;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SAMPLE RUN:
press 1 for Celcius to Fahrenheight and 2 for Fahrenheit to Celcius conversion:1
Enter Temperature in Celcius:200
Temprature in Fahrenheit is:
392
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.