Global Variables are outside functions - C++ Function

C++ examples for Function:Global Variable

Description

Global Variables are outside functions

Demo Code

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

Result


Related Tutorials