Hi All,
This is my question:
Write a function that counts the number of times it is called. Name the function count_it(). Do not pass it anything. In the body of count_it(), print the following message:
The number of times this function has been called is: ###
where ### is the number. (Hint: Because the variable must be local, make it static and initialize it to zero when you first define it.)
Here is what I did... Is there any way to make it better? different way?
Thank you :p
Code:#include <iostream>
using namespace::std;
count_it(); //prototypes
second();
main()
{
count_it();
second();
return 0;
}
count_it() // this function counts how many time it has been called
{
static int count = 0;
count++;
cout << "The number of times this function has been called is " << count << "\n";
return 0;
}
second() //another function that calls count_it()
{
count_it();
return 0;
}