How to Convert Temperature from Celsius to Fahrenheit in C++

Temperature is the physical property that actually expresses the intensity of hotness or coldness. There are two standard units to measure temperature, one is degree Celsius and the other one is degree Fahrenheit. Some of the countries including USA use Fahrenheit to measure the temperature and many other use degrees Celsius as the measure of temperature. To convert temperature from degree Celsius to degree Fahrenheit is easy because there is a simple formula to convert from one quantity to another. Following is the step by step guide to write a code in C++ that will convert the temperature value from Celsius to Fahrenheit.

Instructions

  • 1

    The formula which is used to calculate temperature in Fahrenheit, given that you have temperature value in degree Celsius is given below:


    F = (9/5*C) + 32


    Where F is the temperature value in Fahrenheit and C is the value of temperature in degree Celsius.


    So to calculate the value of temperature in Fahrenheit, you have to multiply the temperature value in degree Celsius with a factor (9/5) and then have to add 32 in it. This is the calibrated formula for conversion and gives accurate results.

  • 2

    Now to write a C++ code to perform the conversion, a simple method to convert the value is written below and which will be used by main method of our code to perform the conversion.


    Conversion Method:


    double CelToFah(double tempInC){
    double Fahrenheit = ((9.0/5.0) * tempInC) + 32.0;
    return Fahrenheit;
    }



    The above method will take value of temperature in degree Celsius as an input and then will convert the value in Fahrenheit and will return it to the calling method.

  • 3

    Now the main method that is written below will call the CelToFah(double) method to perform the conversion.


    int main ( ){


    double temp;


    cout<<”Please enter the value of temperature in Degree Celsius : ”;


    cin>>temp;


    double f = CelToFah(temp);    //value in Fahrenheit will be return in f


    cout<<”The equivalent temperature value in Fahrenheit is:   ”<


    return 0;


    }





    The above two methods will now perform perfectly to do the conversion of temperature from degree Celsius to Degree Fahrenheit.

    You can also use the formula to calculate the values manually.

Leave a Reply

Your email address will not be published. Required fields are marked *


× one = 1