BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan

BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan (http://bzupages.com/index.php)
-   Object Oriented Programming (http://bzupages.com/forumdisplay.php?f=300)
-   -   Program to convert temperatures from Celsius to Fahrenheit and vice versa (http://bzupages.com/showthread.php?t=14667)

bonfire 09-03-2011 12:20 AM

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();
}
This program takes in the user's choice choice as a screen input from the user.
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.