C++ examples for Function:Global Variable
Global Variables are outside functions
#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; }