top of page
Writer's pictureThe Tech Platform

Write a Program to convert the temperature in C++

Algorithm: Temperature Conversion

This algorithm inputs a temperature in Fahrenheit and converts into centigrade.

  1. Start

  2. Input Temperature in Fahrenheit in F variable.

  3. Calculate Centigrade C = (F-32) x 5.0 / 9.0

  4. Show temperature in centigrade

  5. Stop




Celsius to Fahrenheit


Code:

#include<iostream>
using namespace std;
 
int main()
{
    float fahrenheit, celsius;
 
    cout << "Enter the temperature  : ";
    cin >> celsius;
    fahrenheit = (celsius * 9.0) / 5.0 + 32;
    cout << "The temperature in Celsius    : " << celsius << endl;
    cout << "The temperature in Fahrenheit : " << fahrenheit << endl;
    return 0;
}

Output:



Fahrenheit to Celsius


Code:

 #include <iostream>
 
 double fahrenheitToCelsius(double fahrenheit)
 {
     double celsius;
 
     celsius = (fahrenheit - 32.0) * 5.0 / 9.0;
     return celsius;
 }
 
 int main()
 {
     double fahrenheit;
 
     std::cout << "Enter temperature in fahrenheit (in degrees) ";
     std::cin  >> fahrenheit;
     std::cout << "Temperature in Celsius (in degrees) = "
               << fahrenheitToCelsius(fahrenheit) << std::endl;
 }

Output:



The Tech Platform

Comments


bottom of page