Simple Question Regarding Functions

I'm just starting to learn c++, and I'm having trouble understanding why this doesnt work. This prints out "1" instead of the actual calculation of "8." Why is this way incorrect?

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
using namespace std;


int volume (int l, int w, int h){
    l*w*h;
}

int main(){
    cout << volume(2,2,2) << endl;
}


Thanks for the help!
you shold return a value to the main function .



for example .
1
2
3
4
5
6
7
int volume (int l, int w, int h){

int V ; 
  V=  l*w*h;

return V ; 
}



remember to declare V in your main function .
Last edited on
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
using namespace std;


int volume (int l, int w, int h){
    return l*w*h;//<<<<<<<
}

int main(){
    cout << volume(2,2,2) << endl;
}
Topic archived. No new replies allowed.