C++ if-else Statement to check char type value

Description

C++ if-else Statement to check char type value

#include <iostream>
#include <iomanip>
using namespace std;
// A temperature conversion program
int main()//from   www . ja  v a  2 s . c  om
{
   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;
}



PreviousNext

Related