Temperature conversion script doest work with negative input value

1 回表示 (過去 30 日間)
Callum Davies
Callum Davies 2022 年 12 月 23 日
編集済み: Image Analyst 2022 年 12 月 23 日
I've made a script that converts Farenheit to Celsius and Kelvin, but when the input value is negative the script breaks and gives incorrect values. how can i fix this?
% input the temperature in farenheit
F=input('Input the temperature in Farenheit that you want to convert to Celsius and Kelvin:');
% calculate the temperature in celsius
C=5/9*((F)-32);
%calculate the tempurature in kelvin
K=C+273;
% output the temperature in celsius and kelvin
disp([num2str(F),' degrees Farenheit is ',num2str(C),' degrees Celsius and ',num2str(K),' degrees Kelvin'])
  1 件のコメント
Torsten
Torsten 2022 年 12 月 23 日
Disregarding the fact that "Farenheit" should be "Fahrenheit", your code works just fine.

サインインしてコメントする。

採用された回答

John D'Errico
John D'Errico 2022 年 12 月 23 日
編集済み: John D'Errico 2022 年 12 月 23 日
Nope. Works just fine. For example, with F = -459 (approximately absolute zero) you should get approximately -273.
F=input('Input the temperature in Farenheit that you want to convert to Celsius and Kelvin:');
Input the temperature in Farenheit that you want to convert to Celsius and Kelvin:-459
F
F =
-459
C=5/9*((F)-32)
C =
-272.78

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeChemistry についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by