Functions are useful in a variety of programming applications.  On the basic level, functions allow us to send values to functions, which then preform computations and return a value.  In our previous tutorials we have become familiar with the main() function.  In this tutorial we will learn the basics of using functions by creating a small program that uses a function to compute sales tax.

/* Calculating Sales Tax
   Nathan Neil */
   #include <iostream>
   #include <cstdlib>
   using namespace std;
   float tax (float x);
   int main() {
   	float price;
   	//ask for the price
   	cout << "How much is the item: ";
   	cin >> price;
   	cout << "The price of the item is: " << price << "\n";
   	//find tax
   	float salestax = tax(price);
	cout << "The amount of tax is :" << salestax << "\n";
	cout << "The total is: " << (salestax + price);
	   return 0;
    float tax (float x){
    	float result = x * .06;
    	return result;


Pin It on Pinterest

Share This

Share this post with your friends!

%d bloggers like this: