Functions - Examples

Hey guys, i don't know anything yet about functions and "passing arguments/parameters" ....but it would be discussed on our next c++ class..

Can you please give/post a very simple program with the following conditions:


1) Functions with no return value and without passing arguments/parameters
2) Functions with no return value but with passing arguments/parameters
3) Functions with return value but without passing arguments/parameters
4) Functions with return value and with passing arguments/parameters
1) Functions with no return value and without passing arguments/parameters:

1
2
3
4
5
void func1(){
      
      cout << "Hello";
    
}


2) Functions with no return value but with passing arguments/parameters
1
2
3
4
5
6
7
void func2(name){

    cout << "Hello, " << name;

}


3) Functions with return value but without passing arguments/parameters
1
2
3
4
5
6
int divide(){

   int answer = 35 \ 7;
   
 return answer;
}


4) Functions with return value and with passing arguments/parameters
1
2
3
4
5
6
7
double average(num1, num2, num3){
    
    double avg;
    avg = (num1 + num2 + num3) / 3;

    return avg;
}


Topic archived. No new replies allowed.