Functions
Functions
Software Development
Function
What is a function?
int main()
{
double price, bill;
int number;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout << number << " items at " << "$" << price << " each. \n" <<"Final bill, including tax, is $" << bill
<< endl;
system("pause");
return 0;
}
double total_cost(int number_par, double price_par)
{
const double TAX_RATE = 0.05; //5% sales tax
double subtotal;
subtotal = price_par * number_par;
return (subtotal + subtotal*TAX_RATE);
}
The return statement
• A return statement consists of the keyword return
followed by an expression.
• Example
return (subtotal + subtotal * tax);
or
return subtotal + subtotal * tax;
Function Call
• A function call is an expression consisting of
the function name followed by arguments
enclosed in parentheses.