Sum of all elements of a vector

Hello all,

I have a vector with float values and doubles, I am trying to sum all the elements of the vector. The problem is: it is only considering the number before decimal point.

 
  sum_of_elems = std::accumulate(MyVector.begin(), MyVector.end(), 0);  //this is what i m doing 


This is the data in the vector.
 
0,0,0.00737798,0.00737798,0.00737798,0.00737798,0.00737798,0.00737798,0.00737798,0,0


I need exact sum to calculate exact mean.
Last edited on
Hi,

this should work
sum_of_elems = std::accumulate(MyVector.begin(), MyVector.end(), 0.0);
http://ideone.com/cD0mz5

Hope this helps
Last edited on
thank you!
Topic archived. No new replies allowed.