C++

C++ Program to Convert Celsius to Fahrenheit2 min read

In this program Converts Temperature from Celsius to Fahrenheit.

C++ Code:




Output:

cpp examples
cpp examples

Here’s an explanation of each line in the code:

This line includes the iostream library, which provides input and output functionality.

This line specifies that the standard namespace should be used, which makes it possible to use the standard library functions without having to qualify them with the namespace name.

This line declares the main function, which is the entry point for the program. The int return type indicates that the function returns an integer value.

These two lines declare two variables cel and far of type float, which are used to store the temperature in Celsius and Fahrenheit, respectively.

This line uses the cout stream to output a message prompt to the user asking for the temperature in Celsius.

You may also like: C++ Programs Examples with Explanation

This line uses the cin stream to input a value from the user and store it in the cel variable.

This line converts the temperature from Celsius to Fahrenheit using the formula (cel * 9.0) / 5.0 + 32, and stores the result in the far variable.

This line outputs the converted temperature in Fahrenheit using the cout stream.

This line returns 0 to indicate that the main function has executed successfully.

Leave a Comment