In this program, we will learn about converting the given temperature from Celsius to Fahrenheit. Here you will learn how an arithmetic expressions is used in a C++ program.
Code for C++ Program to convert Celsius to Fahrenheit:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#include<iostream> using namespace std; int main() { float celsius; // taking input in degree celsius cout << "Enter the temperature in celsius: "; cin >> celsius; // calculating fahrenheit float fahrenheit = (celsius * 1.8) + 32; // printing fahrenheit cout << "The temperature is " << fahrenheit << " degree fahrenheit."; return 0; } |
Output:
1 2 3 4 5 6 7 8 |
Enter the temperature in celsius: 85 The temperature is 185 degree fahrenheit. Enter the temperature in celsius: -40 The temperature is -40 degree fahrenheit. |