Create an Temperature Conversion in C++ with Free Codes

Introduction

Here we are going to create an Temperature Conversion in C++ Which Converts the temperature between Celsius, Fahrenheit, and Kelvin. Here is the simple overview of the Project and formulas which we used for create Temperature Conversion.

Overview of Temperature Conversion

The temperature converter will offer the following conversion options:

  1. Celsius to Fahrenheit
  2. Fahrenheit to Celsius
  3. Celsius to Kelvin
  4. Kelvin to Celsius
  5. Fahrenheit to Kelvin
  6. Kelvin to Fahrenheit

The user selects a conversion option, inputs the temperature, and the program outputs the converted temperature.

Formulas for Temperature Conversion

Celsius to Fahrenheit:

F = C× 5/9 + 32

where F is the temperature in Fahrenheit and C is the temperature in Celsius.

Fahrenheit to Celsius:

C =(F−32) × 5/9

where C is the temperature in Celsius and F is the temperature in Fahrenheit.

Celsius to Kelvin:

K = C + 273.15

where K is the temperature in Kelvin and C is the temperature in Celsius.

Kelvin to Celsius:

C = K − 273.15

where C is the temperature in Celsius and K is the temperature in Kelvin.

Fahrenheit to Kelvin:

K =(F−32)× 5/9 + 273.15

where K is the temperature in Kelvin and F is the temperature in Fahrenheit.

Kelvin to Fahrenheit:

F =(K−273.15)× 9/5 +32

where F is the temperature in Fahrenheit and is the temperature in Kelvin.

Project Codes

Here is the Complete Project Codes

#include <iostream>
using namespace std;

int main() {
    char choice;
    double temperature, convertedTemperature;

    // Display available conversion options
    cout << "Temperature Converter" << endl;
    cout << "Select conversion option:" << endl;
    cout << "1. Celsius to Fahrenheit" << endl;
    cout << "2. Fahrenheit to Celsius" << endl;
    cout << "3. Celsius to Kelvin" << endl;
    cout << "4. Kelvin to Celsius" << endl;
    cout << "5. Fahrenheit to Kelvin" << endl;
    cout << "6. Kelvin to Fahrenheit" << endl;
    cin >> choice;

    // Input the temperature to convert
    cout << "Enter the temperature: ";
    cin >> temperature;

    // Perform the chosen conversion
    switch(choice) {
        case '1':
            convertedTemperature = (temperature * 9/5) + 32;
            cout << "Result: " << temperature << " Celsius = " << convertedTemperature << " Fahrenheit" << endl;
            break;
        case '2':
            convertedTemperature = (temperature - 32) * 5/9;
            cout << "Result: " << temperature << " Fahrenheit = " << convertedTemperature << " Celsius" << endl;
            break;
        case '3':
            convertedTemperature = temperature + 273.15;
            cout << "Result: " << temperature << " Celsius = " << convertedTemperature << " Kelvin" << endl;
            break;
        case '4':
            convertedTemperature = temperature - 273.15;
            cout << "Result: " << temperature << " Kelvin = " << convertedTemperature << " Celsius" << endl;
            break;
        case '5':
            convertedTemperature = (temperature - 32) * 5/9 + 273.15;
            cout << "Result: " << temperature << " Fahrenheit = " << convertedTemperature << " Kelvin" << endl;
            break;
        case '6':
            convertedTemperature = (temperature - 273.15) * 9/5 + 32;
            cout << "Result: " << temperature << " Kelvin = " << convertedTemperature << " Fahrenheit" << endl;
            break;
        default:
            cout << "Error: Invalid option!" << endl;
            break;
    }

    return 0;
}

To Do List - E-Books

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top