How to write the code that takes input as fahrenheit and display Celsius?

조회 수: 5 (최근 30일)
Hi all,
I want to write down the code that takes an input and covert it to the desired answer. for example,
f = input('Enter temperature in Fahrenheit:')
c = (f-32)*5/9;
fprintf('The corresponding temperature in Celsius is: %2.2f','c')
Can you please tell me why this is not working?
  댓글 수: 3
Ashfaq Ahmed
Ashfaq Ahmed 2022년 1월 1일
Hi, I did that but it does not display the sentence I want to see. Although the converted result is there, in the workspace.
Shreyan Basu Ray
Shreyan Basu Ray 2022년 1월 1일
Try to put in the value of f, instead of getting it from the user. Say,
f = 100;
c = (f-32)*5/9;
fprintf('The corresponding temperature in Celsius is: %2.2f',c)
Now you should be able to see. This is happening because, here in this particular workspace, Matlab is not having any support for user input.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2022년 1월 1일
f = input('Enter temperature in Fahrenheit: ')
c = (f-32)*5/9;
fprintf('The corresponding temperature in Celsius is: %2.2f\n', c)
  댓글 수: 4
Ashfaq Ahmed
Ashfaq Ahmed 2022년 1월 1일
Hi, thanks.
I am expectig to see this sentence first -
'Enter temperature in Fahrenheit: '
Then, when I input the F temperature, I want to see the result with this sentence -
'The corresponding temperature in Celsius is: '
Ashfaq Ahmed
Ashfaq Ahmed 2022년 1월 1일
편집: Ashfaq Ahmed 2022년 1월 1일
I can see it now. Thank you!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by