Using Variables with Functions - C++ Function

C++ examples for Function:Function Creation

Description

Using Variables with Functions

Demo Code

#include <iostream> 
   //from   w ww . j a  v a  2s .c o  m
float convert(float); 
   
int main() 
{ 
    float fahrenheit; 
    float celsius; 
   
    std::cout << "Please enter the temperature in Fahrenheit: "; 
    std::cin >> fahrenheit; 
    celsius = convert(fahrenheit); 
    std::cout << "\nHere's the temperature in Celsius: "; 
    std::cout << celsius << "\n"; 
    return 0; 
} 
   
// function to convert Fahrenheit to Celsius 
float convert(float fahrenheit) 
{ 
    float celsius; 
    celsius = ((fahrenheit - 32) * 5) / 9; 
    return celsius; 
}

Result


Related Tutorials