C++

Write a program to convert Fahrenheit into Celsius in C++ program

Write a program to convert Fahrenheit into Celsius in C++ program

In this article, we will discuss the concept of  Write a program to convert Fahrenheit into Celsius in the  C++ program

In this post, we will learn how to write a program to Convert Fahrenheit into Celsius. Here, we have four methods and explain how to calculate Celsius and display the result on the screen in C++ programming language.

Code to Convert Fahrenheit into Celsius

Convert Fahrenheit into Celsius  -#1

In this program, the user declares two variables as Celsius and Fahrenheit and initiates the value as 200.20 to Celsius. Then the scientific equation will convert it from Fahrenheit into Celsius in the C++ programming language.

Program 1

//C++ program to convert F into C
#include <iostream>
using namespace std;
int main() {
    float celsius, fahrenheit;
     //declare float type variable
   fahrenheit=200.20;
    //Calculate celsius
  //Using equation
    celsius=((fahrenheit-32) * 5/9);
    cout<<fahrenheit<<" Fahrenheit is: "<<celsius <<" Celsius";
    //display result on the screen

    return 0;
}

When the above code is executed, it produces the following result

200.2 Fahrenheit is: 93.4444 Celsius

 

Convert Fahrenheit into Celsius  -Entered by the user-#2

In this program, the user declares two variables as Celsius and Fahrenheit. The program asks for the value from the user to Fahrenheit then the given input will convert from Fahrenheit into Celsius in the C++ programming language using the scientific equation.

Program 2

//C++ program to convert F into C
#include <iostream>
using namespace std;
int main() {
    float celsius, fehrenheit;
    //declare float type variables
    // ask input from the user
    cout<<"Enter the temperature in fehrenheit:";
  cin>>fehrenheit;//reading the input
    //Calculate Fahrenheit
    celsius=((fehrenheit-32) * 5/9);
    cout<<fehrenheit<<" Fehrenheit is: "<<celsius <<" Celsius";
    //display result on the screen

    return 0;
}

When the above code is executed, it produces the following result

Enter the temparature in fehrenheit:50.50
50.5 Fehrenheit is: 10.2778 Celsius

 

Convert Fahrenheit into Celsius  -Using function-#3

In this program, the user declares a double variable as a parameter for Fahrenheit in the user-defined function. When the user runs the program (when calling the function), the value for Fahrenheit passes as an argument to the function.
Finally, the Celsius value is calculated and displayed on the screen using the scientific equation.

Program 3

//C++ program to convert F into C using function
#include <iostream>
using namespace std;
float fahrenheitToCelsius(float);
//function prototype
int main() {
    float fahrenheit;
    //declare float type variables
    //Calculate Fahrenheit
  //Calling the function with an argument
    float celsius=fahrenheitToCelsius(32.00);
    float celsius1=fahrenheitToCelsius(212.00);
    float celsius2=fahrenheitToCelsius(100.50);
    float celsius3=fahrenheitToCelsius(98.4);
  
    //display result on the screen
cout<<celsius <<" Celsius"<<endl;
cout<<celsius1 <<" Celsius"<<endl;
cout<<celsius2 <<" Celsius"<<endl;
cout<<celsius3 <<" Celsius"<<endl;
    return 0;
}//function definition
float fahrenheitToCelsius(float fahrenheit){
return ((fahrenheit-32) * 5/9);;
}

When the above code is executed, it produces the following result

0 Celsius
100 Celsius
38.0556 Celsius
36.8889 Celsius

 

 

Convert Fahrenheit into Celsius Using the function-Entered by the user-#4

In this program, the user declares a double variable as a parameter for Fahrenheit in the user-defined function. When the user runs the program (when calling the function), The program asks for the value from the user to Fahrenheit and the value for Fahrenheit passes as an argument to the function.
Finally, the Celsius value is calculated and displayed on the screen using the scientific equation.

Program 4

//C++ program to convert F into C using function
#include <iostream>
using namespace std;
float fahrenheitToCelsius(float);
//function prototype
int main() {
    float fahrenheit;
    //declare float type variables
  // ask input from the user
    cout<<"Enter the temperature in Fahrenheit:";
  cin>>fahrenheit;//reading the input
    //Calculate Fahrenheit
    float celsius=fahrenheitToCelsius(fahrenheit);
  //Calling the function with an argument
    //display result on the screen
  
cout<<fahrenheit <<" Fahrenheit"<<" equal to "<<celsius<<" Celsius"<<endl;
    return 0;
}//function definition
float fahrenheitToCelsius(float fahrenheit){
return ((fahrenheit-32) * 5/9);;
}

When the above code is executed, it produces the following result

Enter the temperature in Fahrenheit:110.00
110 Fahrenheit equal to 43.3333 Celsius

 

Similar post

Celsius into Fahrenheit in C program

Fahrenheit into Celsius in C program

Celsius into Fahrenheit in C++ program

Fahrenheit into Celsius in C++ program

 

Karmehavannan

Recent Posts

Subtract two numbers using method overriding

Subtract two numbers using method overriding   Program 1

3 months ago

PHP Star triangle Pattern program

PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…

3 months ago

Using function or method to Write temperature conversion : Fahrenheit into Celsius

Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…

1 year ago

Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user

Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…

1 year ago

Write temperature conversion program: Fahrenheit into Celsius

Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…

1 year ago

How to write a program to convert Fahrenheit into Celsius

How to write a program to convert Fahrenheit into Celsius In this article, we will…

1 year ago

This website uses cookies.