it feels a bit stupid to ask such a question here but it is really suprising, that the function is not returning a decimal point value. Here is my function
1 2 3 4 5 6
int meanValueFunction(vector<int> arrayValues){
int sum = 0;
sum = sumFunction(arrayValues);
float meanValue = sum/arrayValues.size();
cout<< meanValue << endl;
return meanValue;
i want result in decimal point i.e 27.2 for the values (2 4 20 10 100) but it returns 27 instead. Am i making any mistakes?
Both 'sum' and 'size()' are integers... so the result of this division will be an integer.
To fix... make one of those a floating point. Here, it'd be easier to make sum a float instead of an int.
Also....
1 2 3 4
int meanValueFunction(vector<int> arrayValues){
// ^
// |
// return type
The return type of your function is an int... which means it will return an integer. If you want it to return a floating point, you must change the return type to float.