Converting the Fahrenheit to Celcius degree C++ code sample demonstrating user defined function
Compiler: Visual C++ Express Edition 2005
Compiled on Platform: Windows XP Pro SP2
Header file: Standard
Additional project setting: Set project to be compiled as C++
Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)
Other info: none
To do: Converting the Fahrenheit to Celcius degree C++ code sample demonstrating user defined function
To show: How to convert Fahrenheit to Celcius in C++ programming to demonstrate the user defined function
// the Fahrenheit to Celcius conversion C++ example
#include <iostream>
using namespace std;
// function prototype
float Convert(float);
int main(void)
{
float TempFer;
float TempCel;
cout<<"Please enter the temperature in Fahrenheit: ";
cin>>TempFer;
// function call
TempCel = Convert(TempFer);
cout<<"\n";
cout<<TempFer<<" Fahrenheit = "<<TempCel<<" Celcius"<<endl;
return 0;
}
// function definition
float Convert(float TempFer)
{
// local variable
float TempCel;
TempCel = ((TempFer - 32) * 5) / 9;
// return the result to the calling program
return TempCel;
}
Output example:
Please enter the temperature in Fahrenheit: 222
222 Fahrenheit = 105.556 Celcius
Press any key to continue . . .