C++ Program to Convert Temperature from Fahrenheit to Celsius and Celsius to Fahrenheit (If-else statement)
In C++ programming language we can write a program to convert temperature from Fahrenheit to Celsius and Celsius to Fahrenheit with the simple use ofIf-else statement.Let's us look at the code.
C++ Program to Convert Temperature from Fahrenheit to Celsius and Celsius to Fahrenheit (If-else statement)
#include <iostream.h>
int main() {
int choice ;
float temp, countemp ;
std::cout<<"Temperature conversion Menu"<<"\n" ;
std::cout<<"1. Fahrenheit to Celsius"<<"\n" ;
std::cout<<"2. Celsius to Fahrenheit"<<"\n" ;
std::cout<<"Enter your choice:" ;
std::cin>>choice;
if( choice == 1)
{
std::cout<<"\n"<<" Enter temperature in Fahrenheit :" ;
std::cin >> temp ;
countemp = (temp -32) / 1.8 ;
std::cout<<" The temperature in Celsius is : " << countemp <<"\n" ;
}
else
{
std::cout<<"\n" << "Enter temperature in Centigrade : " ;
std::cin >> temp ;
countemp = 1.8 * temp + 32 ;
std::cout<<" The Temperature in Fahreheit is : " << countemp <<"\n" ;
}
return 0 ;
}
The output of the Above Code