CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Mar 2017
    Posts
    6

    How to convert Fahrenheit to Celsius?

    How do I write a program that converts asks the user to enter a temperature in Fahrenheit, reads the
    entered value, converts it to Celsius using the formula and prints the value to
    the console?

    Needs to use this: T C=(T F−32)⋅5/9

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    Re: How to convert Fahrenheit to Celsius?

    use cin >> to obtain the temperature in Fahrenheight (say f as type double), then use cout << to display the converted value

    Code:
    double f;
    cin >> f;
    cout << (f - 32.0) * 5.0 / 9.0 << endl;
    Is this a homework assignment?
    Last edited by 2kaud; March 25th, 2017 at 11:43 AM.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  3. #3
    Join Date
    Mar 2017
    Posts
    6

    Re: How to convert Fahrenheit to Celsius?

    Yes a homework and These are are the hardest problems for me

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    Re: How to convert Fahrenheit to Celsius?

    Have a look at http://forums.codeguru.com/showthrea...ork-assignment so you can get an idea as to the amount of help we'll be able to provide for homework type questions.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  5. #5
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    Re: How to convert Fahrenheit to Celsius?

    [Thread moved from Visual c++ forum as visual c++ not used]
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  6. #6
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    Re: How to convert Fahrenheit to Celsius?

    Quote Originally Posted by jamsdolpw View Post
    Yes a homework and These are are the hardest problems for me
    If you are taking a c++ course and have had these exercises set as homework, I don't understand how these could be considered 'hardest problems' as they are quite trivial. What has your instructor covered and what book has been suggested?

    Have you actually written yet a c++ program that compiled correctly and was able to be executed OK? if so for what?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  7. #7
    Join Date
    Mar 2017
    Posts
    105

    Re: How to convert Fahrenheit to Celsius?

    Please don't ask homework assignments until you have done enough progress which is satisfactory.
    Though you can do it like this:

  8. #8
    Join Date
    Mar 2017
    Posts
    105

    Re: How to convert Fahrenheit to Celsius?

    Code:
    Code:
    #include<iostream>
    using namespace std;
    
    int main ()
    {
        double f;
        double c;
    
        cout <<"Enter the Farenheit value" << endl;
        cin >> f;
    
        c=(f-32)*5/9;
        cout << " The Celsius value is:"<< c << endl;
    
        return 0;
    }
    Last edited by 2kaud; March 29th, 2017 at 05:41 AM. Reason: Added code tags

  9. #9
    Join Date
    Mar 2017
    Posts
    105

    Re: How to convert Fahrenheit to Celsius?

    Thanks for editing

  10. #10
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    Re: How to convert Fahrenheit to Celsius?

    [When posting code, please use code tags so that the code is readable. Go Advanced, select the formatted code and click '#'.]
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured