Q:

C++ Program To Convert Celsius To Fahrenheit And Vice Versa Using Switch Case

0

Logic:-

 For Converting Temperature Celsius to Fahrenheit, we are using a given Formula. We have just take a value or temperature in Celsius or Fahrenheit by the user and put the values in given formula and print the outcome given by formula on screen. Here in this problem we are given three option to the user and user have to choose any one of the first choices is Celsius To Fahrenheit, the second choice is Fahrenheit To Celsius and the Last one is Exit without testing any one of the queries.

 

Formula's

Celsius To Fahrenheit:-

Fahrenheit=(Celsius*9/5)+32;

Fahrenheit To Celsius:-

Celsius=(Fahrenheit-32)*5/9;

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using if else instead of switch statement:

#include<iostream>
using namespace std;
int main()
{
  int a;
  cout<<"1. For Celsius To Fahrenheit. \n";
  cout<<"2. For Fahrenheit To Celsius. \n";
  cout<<"3. For Exit\n\n";
  cout<<"Enter Your Choice \n ";
  cin>>a;
  
    double cel,feh;
    if(a==1)
    {
        cout<<"Enter The Temperature In Celsius\n";
        cin>>cel;
        feh=(cel*9/5)+32;
        cout<<"\nTemperature In Fahrenheit Is = "<<feh ;
    }
    else if(a==2)
    {
        cout<<"Enter The Temperature In Fahrenheit\n";
        cin>>feh;
        cel=(feh-32)*5/9;
        cout<<"\nTemperature In Celsius Is = "<<cel ;
    }
    else if(a==3)  
    exit(0);
    else 
    cout<<"\nEnter The Right Choice \n";
}

need an explanation for this answer? contact us directly to get an explanation for this answer
need an explanation for this answer? contact us directly to get an explanation for this answer

#include<iostream>
using namespace std;
int main()
{
  int a;
  cout<<"1. For Celsius To Fahrenheit. \n";
  cout<<"2. For Fahrenheit To Celsius. \n";
  cout<<"3. For Exit\n\n";
  cout<<"Enter Your Choice \n ";
  cin>>a;
  switch(a)
   { 
    double cel,feh;
    case 1: cout<<"Enter The Temperature In Celsius\n";
      cin>>cel;
      feh=(cel*9/5)+32;
      cout<<"\nTemperature In Fahrenheit Is = "<<feh ;
    break;
   
   case 2: cout<<"Enter The Temperature In Fahrenheit\n";
      cin>>feh;
      cel=(feh-32)*5/9;
      cout<<"\nTemperature In Celsius Is = "<<cel ;
    break;
      
   case 3:exit(0);
   
   default:cout<<"\nEnter The Right Choice \n";
    break;     
   }
}

 

Output:

1. For Celsius To Fahrenheit. 

2. For Fahrenheit To Celsius. 

3. For Exit

Enter Your Choice 

 1

Enter The Temperature In Celsius

37

Temperature In Fahrenheit Is = 98.6

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (2)

C++ Program For Arithmetic Operations Using Switch... >>