# C++ program for temperature conversion

In this article, you will learn a C++ program for temperature conversion. The user can select and enter any of the temperatures from Celsius, Fahrenheit, or Kelvin and the program displays its corresponding temperatures on the console screen.

## Formula

Here are the formulas for temperature conversion.

## Example: Temperature conversion in C++

``````#include<iostream>
using namespace std;

int main()
{
float fahr, cel, kel;
char option;

cout << "Choose One Option:" << endl;
cout << "1: For Celsius" << endl;
cout << "2: For Fahrenheit" << endl;
cout << "3: For Kelvin" << endl;
cin >> option;

if (option == '1')
{
cout << "Enter the temperature in Celsius: ";
cin >> cel;

fahr = (1.8 * cel) + 32.0;
kel =  cel + 273;

cout << "\nTemperature in  Fahrenheit: " << fahr << " F" << endl;
cout << "\nTemperature in  Kelvin: " << kel << " K" << endl;
}
else if (option == '2')
{
cout << "Enter the temperature in Fahrenheit: ";
cin >> fahr;

cel = (fahr - 32) / 1.8;
kel = 0.55 * (fahr - 32) + 273;

cout << "\nTemperature in  Celsius: " << cel << " C" << endl;
cout << "\nTemperature in  Kelvin: " << kel << " K" << endl;
}
else if (option == '3')
{
cout << "Enter the temperature in Kelvin: ";
cin >> fahr;

cel = kel - 273;
fahr = 1.8 * (kel - 273) + 32;

cout << "\nTemperature in  Celsius: " << cel << " C" << endl;
cout << "\nTemperature in  Fahrenheit: " << fahr << " F" << endl;
}
else
cout << "Wrong Input." << endl;

return 0;
}``````

Scroll to Top