How do i do a function?

I'm taking a basic class of programing but we're kind of slow and i want to know hot to do a function and how does it work. If the answer can be with an example it would be very helpful.
This is an example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>

int Add( int a, int b ) {
    return a + b;
}

int main( int argc, char* argv[] ) {
    std::cout << "Enter an integer: ";
    int num1;
    std::cin >> num1;

    std::cout << "Enter another integer: ";
    int num2;
    std::cin >> num2;

    std::cout << "The sum is " << Add( num1, num2 ) << std::endl;

    std::cin.get();
    std::cin.get();

    return 0;
}


The program basically asks the user to enter two integers, then calls the function Add taking num1 and num2 as arguments for the parameters ( int a, int b ). Add returns the sum of num1 and num2 , and the program outputs that sum. Have a look here for a full explanation of functions: http://cplusplus.com/doc/tutorial/functions/ and http://cplusplus.com/doc/tutorial/functions2/ and at http://www.learncpp.com chapter 1.4 and chapter 7.
Good luck!
Why / What does std::cin and std::cout do? Is it essentially the same thing as namespace std without declaring it?
Exactly.
thanks fransje it was very helpful
Topic archived. No new replies allowed.