C++ Program for temperature conversion(Fahrenheit to Celsius and vice versa)

//Temperature scale conversion
#include<iostream>
using namespace std;
int main()
{
    double tin,tout;
    int choice;
    char cont;
    a:cout<<"What do you want to do?\n\n";                //Get the choice of the user
    cout<<"1.Fahrenheit to Celsius\n2.Celsius to Fahrenheit"<<endl;
    cout<<"\nEnter either '1' or '2'"<<endl;
    cin>>choice;
    if (choice==1)
    {
    cout<<"\nEnter the temperature in Fahrenheit"<<endl;        //Get the temp in Fahrenheit
    cin>>tin;
    tout=(tin-32.0)*5.0/9.0;                    //Use the conversion Formula
    cout<<"\nThe temperature in Celsius is "<<tout<<endl;        //Print the answer
    cout<<"\nWant to continue?, Y or N"<<endl;            //Ask the user if they want to continue
    cin>>cont;
    if (cont=='Y'||cont=='y')
    goto a; 
    }
     
    else if (choice==2)
    {
     cout<<"\nEnter the temperature in Celsius"<<endl;        //Get the temp in Celsius
    cin>>tin;
    tout=9*tin/5+32;                        //Use the conversion Formula
    cout<<"The temperature in Fahrenheit is "<<tout<<endl;        //Print the answer
    cout<<"\nWant to continue?, Y or N"<<endl;
    cin>>cont;
    if (cont=='Y'||cont=='y')
    goto a;
    }
     
    else
    {
    cout<<"Enter a valid choice"<<endl;
    goto a;
     }
    return 0;
}
[wpedon id="7041" align="center"]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.