VOOZH about

URL: https://www.geeksforgeeks.org/cpp/temperature-converter-in-cpp/

⇱ Temperature Converter in C++ - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Temperature Converter in C++

Last Updated : 19 Jul, 2025

In this project, you will build a simple command-line application that allows users to convert temperatures between Celsius and Fahrenheit. The program should take the user’s choice, perform the appropriate conversion, and display the result. It should continue running based on the user's input and handle invalid choices appropriately, as described in the features below.

Features

Our temperature converter program will have the following features:

  • Convert Celsius to Fahrenheit
  • Convert Fahrenheit to Celsius
  • Validate user input for menu selection
  • Keep running until the user chooses to exit

Example:

Try to solve this yourself before looking at the solution below.

Project Requirements

You must be familiar with the following topics in C++:

  • Variable, Data Types and Constants
  • Basic input/output
  • Operators
  • Decision Making and Loops

Implementation

We start by defining constexpr constants for the conversion factors.

Then, we use a while (true) loop to keep the converter running. Inside the loop, we display a menu and take user input. Based on the input, the appropriate conversion is performed. Input is validated to handle invalid menu choices.

Execution

When you compile and run the program, it displays:

Summary

In this project, we learned:

  • How to create a simple temperature converter using cin and cout
  • How to use constexpr to define conversion factors
  • How to use conditional statements to handle menu choices
  • How to use a while loop to allow multiple conversions until exit

You can also extend this program to support kelvin (K) also.

Comment
Article Tags:
Article Tags: