Program to convert temperatures from Celsius to Fahrenheit and vice versa 1 Attachment(s) Program to convert temperatures from Celsius to Fahrenheit and vice versa #include #include void main() { clrscr(); int choice; float ctemp,ftemp; cout << "1.Celsius to Fahrenheit" << endl; cout << "2.Fahrenheit to Celsius" << endl; cout << "Choose between 1 & 2 : " << endl; cin>>choice; if (choice==1) { cout << "Enter the temperature in Celsius : " << endl; cin>>ctemp; ftemp=(1.8*ctemp)+32; cout << "Temperature in Fahrenheit = " << ftemp << endl; } else { cout << "Enter the temperature in Fahrenheit : " << endl; cin>>ftemp; ctemp=(ftemp-32)/1.8; cout << "Temperature in Celsius = " << ctemp << endl; } getch(); } It then asks the user for a temperature in Celsius or Fahrenheit depending on the choice. It then converts the Celsius temperature to Fahrenheit or vice versa and prints it out using the 'cout' command. Sample Input 2 98.6 Sample Output Temperature in Celcius = 37 |
All times are GMT +5. The time now is 03:10 AM. |
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.