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;
}

PhD researcher at Friedrich-Schiller University Jena, Germany. I'm a physicist specializing in theoretical, computational and experimental condensed matter physics. I like to develop Physics related apps and softwares from time to time. Can code in most of the popular languages. Like to share my knowledge in Physics and applications using this Blog and a YouTube channel.



Leave a Reply

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