Help with result of a function

I just starting writing codes and I'm having a problem getting results from functions. I have this function here I wish to return 3*(x/y);(which is 3*(8.2/3) respectively) but the code keeps returning 0 to me. Can someone explain how I can get it to show me the correct answer, I think I have to use cout but I'm unsure how to make it get the result from my function. Thank you.

1
2
3
4
5
6
7
8
9
10
11
#include <iostream> 
using namespace std; 
#include <cmath>
int fee(double x, int y) {
return 3*(x/y);
}
int main(){
	fee(8.2,3);
	return 0;
} 
Last edited on
It's returning 8. You're just throwing away the returned value because you're not doing anything with it.

When you print it through cout, it prints 8:

http://ideone.com/Pbsvq2
Thank you I understand now. Is it normal for the answer to be 8 instead of 8.2? I thought because it was a double it would maintain the decimal points in my answer.
the function outputs an integer:

1
2
3
4
  int fee(double x, int y)
// ^
// |
// The function's return type 


The equation itself does result in 8.2. However when you return it, it gets cast to the return type, int, which forces it to 8.

If you want to retain the floating point, change the return type to double:

 
double fee(double x, int y)
Topic archived. No new replies allowed.