Converts fahrenheit to centigrade, or centigrade to fahrenheit - C++ Data Type

C++ examples for Data Type:double

Description

Converts fahrenheit to centigrade, or centigrade to fahrenheit

Demo Code

#include <iostream>
using namespace std;
int main()/*from w w  w  .j ava  2  s  . c  o m*/
{
   int response;
   double temper;
   cout << "\nType 1 to convert fahrenheit to celsius," << "\n     2 to convert celsius to fahrenheit: ";
   cin >> response;
   if( response == 1 )
   {
      cout << "Enter temperature in fahrenheit: ";
      cin >> temper;
      cout << "In celsius that's " << 5.0/9.0*(temper-32.0);
   }
   else
   {
      cout << "Enter temperature in celsius: ";
      cin >> temper;
      cout << "In fahrenheit that's " << 9.0/5.0*temper + 32.0;
   }
   cout << endl;
   return 0;
}

Result


Related Tutorials