C++ Program to Convert Fahrenheit to Celsius

«
»
This C++ program performs conversion of temperature from fahrenheit to celsius. The program takes temperature in fahrenheit degrees performs conversion to celsius degrees using a function and prints the value on standard output stream.

Here is the source code of the C++ program performs conversion of temperature from fahrenheit to celsius. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.

  1. /*
  2.  * C++ Program to Perform Fahrenheit to Celsius Conversion
  3.  */
  4.  #include <iostream>
  5.  
  6.  double fahrenheitToCelsius(double fahrenheit)
  7.  {
  8.      double celsius;
  9.  
  10.      celsius = (fahrenheit - 32.0) * 5.0 / 9.0;
  11.      return celsius;
  12.  }
  13.  
  14.  int main()
  15.  {
  16.      double fahrenheit;
  17.  
  18.      std::cout << "Enter temperature in fahrenheit (in degrees) ";
  19.      std::cin  >> fahrenheit;
  20.      std::cout << "Temperature in Celsius (in degrees) = "
  21.                << fahrenheitToCelsius(fahrenheit) << std::endl;
  22.  }

$ a.out
Enter temperature in fahrenheit (in degrees) -40
Temperature in Celsius (in degrees) = -40

Sanfoundry Global Education & Learning Series – 1000 C++ Programs.

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
advertisement
advertisement
If you wish to look at all C++ Programming examples, go to C++ Programs.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & technical discussions at Telegram SanfoundryClasses.