Program to convert temperature 'Celsius to Fahrenheit and from Fahrenheit to Celsius'

This example program is taken from the book C++ IT series,Chapter No.5 program no.5
Write a program that get a number and a letter.If the letter is 'f ' the program treat the number as temperature in Fahreheit and convert it in Celsius.If the entered letter is 'c' the program treat the number as temperature in celsius and convert it in Fahrenheit,and display erroe message if user enter another number-celsius to fahrenheit conversion.

  • convert fahrenheit to celsius
  • convert celsius to fahrenheit





using namespace std;
#include<iostream>
#include<conio.h>
int main()
{
char ch;
int temp;
float f,c;
cout<<"Enter temperature:";
cin>>temp;
cout<<"type 'f' if the given temperature is in fahrenheit:\ntype 'c' if the given temperature is in Celsius:\n";
cin>>ch;
if(ch=='f' ||ch=='F')
  {
  cout<<"Temperature that you enter is = "<<temp<<" fahrenheit"<<endl;
  c=9/5*(temp-32);
  cout<<"Temperature Converted in Celsius = "<<c <<"celsius";
  }
else if(ch=='c' ||ch=='C')
  {
  cout<<"Temperature that you enter is = "<<temp<<"celsius"<<endl;
  f=5/9*(temp-32);
  cout<<"Temperature Converted in Fahrenheit = "<<f<<"fahrenheit";
  }
else
 cout<<"Invalid Input";
getch();      
Output / result
return 0;
     }

Program to convert temperature 'Celsius to Fahrenheit and from Fahrenheit to Celsius' Program to convert temperature 'Celsius to Fahrenheit and from Fahrenheit to Celsius' Reviewed by Shoaib Jameel on 3/08/2017 05:04:00 pm Rating: 5

No comments:

Theme images by mariusFM77. Powered by Blogger.