Wednesday, 26 August 2015

Q) Write and run a program that gives the user only three choices: convert from Fahrenheit to Celsius, convert from Celsius to Fahrenheit, or quit. If the third choice is selected, the program stops. If one of the first two choices is selected, the program should prompt the user for either a Fahrenheit or Celsius temperature, as appropriate, or then compute and display a corresponding temperature. Use the conversion formula

F = (9/5)C + 32
C = (5/9)(F-32)

# include<iostream>
using namespace std;
void main()
{
       int choice;
       float f, c;
       cout<<"To convert your temperature from Celsius to Fahrenheit press 1:"<<endl;
       cout<<"To convert your temperature from Fahrenheit to Celsius press 2:"<<endl;
       cout<<"To quite from the program press 3:"<<endl;
       cout<<"Now Enter Your Choice: ";
       cin>>choice;
       if(choice==1)
       {
               cout<<"enter your temperature in Celsius : ";
               cin>>c;
               f = (9.0/5.0)*c + 32;
               cout<<"Your temperature in Fahrenheit is = "<<f<<"\n";
               cout<<"THANKS \n";
       }
       else if(choice==2)
       {
               cout<<"Enter Your Temperature In Fahrenheit : ";
               cin>>f;
               c = (5.0/9.0)*(f-32.0);
               cout<<"Your temperature in Celsius is = "<<c<<"\n";
               cout<<"THANKS \n";
       }
       else if(choice==3)
               cout<<"You did not want to start conversion\n THANKS\n BYE BYE"<<"\n";
}
system("pause");
}

No comments:

Post a Comment