Second function has its own local variable. - C++ Function

C++ examples for Function:Function Creation

Description

Second function has its own local variable.

Demo Code

#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;                   
}

Result


Related Tutorials