Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c
Function/method to convert Celsius into Fahrenheit -Entered by user

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

Posted on April 12, 2023May 3, 2023

Table of Contents

  • Write a program to convert Fahrenheit into Celsius in C++ program
    • Code to Convert Fahrenheit into Celsius
      • Convert Fahrenheit into Celsius  -#1
      • Convert Fahrenheit into Celsius  -Entered by the user-#2
      • Convert Fahrenheit into Celsius  -Using function-#3
      • Convert Fahrenheit into Celsius Using the function-Entered by the user-#4

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

 

Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes