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

How to write a program to convert Celsius to Fahrenheit in C++

Posted on April 12, 2023April 27, 2023

Table of Contents

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

How to write a program to convert Celsius to Fahrenheit in C++

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

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

Code to Celsius into Fahrenheit

Convert Celsius into Fahrenheit -#1

In this program, the user declares two variables as Celsius and Fahrenheit, and initiates the value as 36.9 to variable- Celsius. It will be converted from Celsius into Fahrenheit in the C programming language using the scientific equation.

Program 1

//C++ code to convert Celsius into Fehrenheit
#include <iostream>
using namespace std;
int main() {
    float celsius, fahrenheit;
    //declare float type variables
    //initialize  variable 
    celsius=36.9;
    //Calculate fahrenheit from celsius
    fahrenheit=(celsius * 9/5)+32;
    cout<<celsius<<" Celsius is same as: "<<fahrenheit <<" Fahrenheit";
    //display result on the screen

    return 0;
}

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

36.9 Celsius is the same as: 98.42 Fahrenheit

 

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

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

Program 2

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

    return 0;
}

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

Enter the temperature in Celsius:99.99
99.99 Celsius is the same as: 211.982 Fahrenheit

 

Convert Celsius into Fahrenheit -Using function-#3

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

Program 3

//C++ program to convert C into F using function
#include <iostream>
using namespace std;
float CelsiusToFahrenheit(float);
//function prototype
int main() {
    float celsius;
    //declare float type variables
    //Calculate Fahrenheit
    float fahrenheit=CelsiusToFahrenheit(32.00);
    float fahrenheit1=CelsiusToFahrenheit(99.00);
    float fahrenheit2=CelsiusToFahrenheit(105.50);
    float fahrenheit3=CelsiusToFahrenheit(37.00);
  //Calling the function with an argument
  
    //display result on the screen
  
cout<<fahrenheit <<" Fahrenheit"<<endl;
cout<<fahrenheit1 <<" Fahrenheit"<<endl;
cout<<fahrenheit2 <<" Fahrenheit"<<endl;
cout<<fahrenheit3 <<" Fahrenheit"<<endl;
    return 0;
}
//function definition
float CelsiusToFahrenheit(float celsius){
return (celsius * 9/5)+32;
}

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

89.6 Fahrenheit
210.2 Fahrenheit
221.9 Fahrenheit
98.6 Fahrenheit

 

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

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

Program 4

//C++ program to convert C into F using function
//with user input
#include <iostream>
using namespace std;
float CelsiusToFahrenheit(float);

int main() {
    float celsius;
    //declare float type variables
  // ask input from the user
    cout<<"Enter the temperature in Celsius:";
  cin>>celsius;//reading the input
    //Calculate Fahrenheit
    float fahrenheit=CelsiusToFahrenheit(celsius);
  //Calling the function with an argument
  
    //display result on the screen
cout<<celsius<<" celsius"<<" equal to "<<fahrenheit <<" Fahrenheit"<<endl;
    return 0;
}
//function definition
float CelsiusToFahrenheit(float celsius){
return (celsius * 9/5)+32;
}

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

Enter the temperature in celsius:111.11
111.11 Celsius equal to 231.998 Fahrenheit

 

Similar post

Celsius into Fahrenheit in the 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