C++ Arithmetic Operator Convert Fahrenheit to Celsius

Description

C++ Arithmetic Operator Convert Fahrenheit to Celsius

#include <iostream>
#include <iomanip>
using namespace std;
// A temperature conversion program
int main()/*from  ww w.j a v  a 2 s  .com*/
{
   char tempType;
   double temp, fahren, celsius;
   cout << "Enter the temperature to be converted: ";
   cin  >> temp;
   cout << "Enter an f if the temperature is in Fahrenheit";
   cout << "\n or a c if the temperature is in Celsius: ";
   cin  >> tempType;
   cout << setiosflags(ios::fixed) << setiosflags(ios::showpoint) << setprecision(2);
   if (tempType == 'f')
   {
      celsius = (5.0 / 9.0) * (temp - 32.0);
      cout << "\nThe equivalent Celsius temperature is " << celsius << endl;
   }
   else
   {
      fahren = (9.0 / 5.0) * temp + 32.0;
      cout << "\nThe equivalent Fahrenheit temperature is " << fahren << endl;
   }
   return 0;
}
#include <iostream>
using namespace std;
int main()/*from   www  .ja  v a  2s  .  c  o  m*/
{
   double fahren, celsius;
   cout << "Enter a temperature in degrees Fahrenheit: ";
   cin  >> fahren;
   celsius = (5.0/9.0) * (fahren - 32.0);
   cout << "The equivalent Celsius temperature is " << celsius << endl;
   return 0;
}



PreviousNext

Related