What if we make our own functions..
1. First we need function prototype. It tells C++, "Hey, I will make my own function!"
2. name of the function
--> myfunc
3. (declare the type of arguments)
: void myfunc(int);
===> This should be above the main function
4. Find the function and pretty much make the function
void myfunc(int x)
{
using namespace std;
cout<<"My favorite number is "<< x << endl;
}
5. call the function
int main()
{
using namespace std;
int num;
cin>>num; //input from the user
myfunc(num);
system("pause");
return 0;
}
Now we can return values in Functions..
int dyear(int); //prototype
int dyear(int d)
{
return 7 * d; //if d=7 --> 49
}
'Computer General > C++ development from the beginning' 카테고리의 다른 글
| Address Operator & Pointer (0) | 2014.12.12 |
|---|---|
| Beginning Loop (0) | 2014.12.12 |
| Beginning Arrays (0) | 2014.12.12 |
| Beginning Math Functions (0) | 2014.12.12 |
| How to start C++ for beginners (0) | 2014.12.10 |