C++ examples for Function:Function Creation
Second function has its own local variable.
#include <iostream> using namespace std; #include <iomanip> int compute_sale(int gallons); int main()//w w w . j a v a2 s . c om { int gallons; cout << "How many gallons of paint did you buy? "; cin >> gallons; compute_sale(gallons); return 0; } int compute_sale(int gallons) { float price_per = 12.45; cout << "The total is " << setprecision(2) << (price_per*(float)gallons) << "\n"; return 0; }