Temperature Converter (Fahrenheit to Celsius)

Before you can do this, you need an IDE first. You can set it up by following this guide.

C++ Homework: Temperature Converter (Fahrenheit to Celsius)

If you have been asked to write a program which accepts temperature in Fahrenheit and print it in centigrade. Then this is how you are supposed to write one.

// Written by: Ryon /*HEADER FILE*/ #include <iostream> #include <cstdlib> using namespace std; /*PROGRAM BODY*/ int main() { //--VARIABLE DECLARATION float fahrenheit, celsius; // Note that we used float to be able to see the accurate value of the converted temperature cout << "Enter the temperature in Fahrenheit: "; cin >> fahrenheit; //--EQUATION FOR CONVERSION celsius = ((fahrenheit-32) * 5) / 9; // To convert Fahrenheit to Celsius // Subtract 32 from the Fahrenheit temperature // Multiply this number by 5 // Divide this number by 9 cout << "The converted temperature of " << fahrenheit << " Fahrenheit is: " << celsius << " Celsius." << endl; system("pause"); return 0; }



The C++ homework is provided by cppforschool. Share this:
Like this:Like Loading...