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

6 views (last 30 days)
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 Comments
Ashfaq Ahmed
Ashfaq Ahmed on 1 Jan 2022
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 on 1 Jan 2022
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.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 1 Jan 2022
f = input('Enter temperature in Fahrenheit: ')
c = (f-32)*5/9;
fprintf('The corresponding temperature in Celsius is: %2.2f\n', c)
  4 Comments
Ashfaq Ahmed
Ashfaq Ahmed on 1 Jan 2022
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: '

Sign in to comment.

More Answers (0)

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!