Create a function in C++

A function is a group of statements that is executed when it is called from some point of the program. The following is its format:

type name ( parameter1, parameter2, ...) { statements }
(via: www.cpulsplus.com)

i have an example of functions to print a sentences and addition of two numbers. Lets see this :
#include <iostream.h>
#include <conio.h>

/*example*/
void sayHi(){
    cout << "Hi There, How are You ? ";
}

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

/*main function*/
void main(){
  sayHi(); /*call sayHi Function*/
  int a = 20, b = 30;
  int c = tambah (a,b);
  cout << c ;

   getch();
   }
Previous
Next Post »