Temperature Converter

Creating a temperature converter in C++ is a relatively simple project that can be a great way to practice input and output operations. Here's a basic example of a Celsius to Fahrenheit and Fahrenheit to Celsius temperature converter:

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

int main() {
    char choice;
    do {
        cout << "Choose an option:\n";
        cout << "1. Convert Celsius to Fahrenheit\n";
        cout << "2. Convert Fahrenheit to Celsius\n";
        cout << "3. Quit\n";
        cout << "Enter your choice (1/2/3): ";
        cin >> choice;

        if (choice == '1') {
            double celsius, fahrenheit;
            cout << "Enter temperature in Celsius: ";
            cin >> celsius;
            fahrenheit = (celsius * 9.0/5.0) + 32;
            cout << "Temperature in Fahrenheit: " << fahrenheit << "°F" << endl;
        } else if (choice == '2') {
            double fahrenheit, celsius;
            cout << "Enter temperature in Fahrenheit: ";
            cin >> fahrenheit;
            celsius = (fahrenheit - 32) * 5.0/9.0;
            cout << "Temperature in Celsius: " << celsius << "°C" << endl;
        } else if (choice == '3') {
            cout << "Goodbye!" << endl;
        } else {
            cout << "Invalid choice. Please enter 1, 2, or 3." << endl;
        }

    } while (choice != '3');

    return 0;
}
```

Output


In this program, the user can select to convert temperatures from Celsius to Fahrenheit or from Fahrenheit to Celsius. The program continues to run until the user chooses to quit (option 3). This is a simple console-based temperature converter, but you can expand it by adding more options or creating a graphical user interface for a more user-friendly experience.
Next Post Previous Post
No Comment
Add Comment
comment url