double numbers[ ] = { 1, 0.5 ,0.333333 ,0.25 ,0.2, 0.166667, 0.142857, 0.125,
0.111111, 0.1 } ;
std::vector doublenumbers ( numb
std::accumulate ( doublenumbers.begin( ) , doublenumbers.end( ) , .0 ) ;
or
std::accumulate ( doublenumbers.begin( ) , doublenumbers.end( ) , (double) 0 ) ;
The type of the "accumulator" variable is the type of the last argument of std::accumulate. You supplied 0 as an argument - an int literal - which means that the accumulator will have type int. The "accumulation" is done in an int accumulator (i.e. rounded to int after each individual summation) and produces int result. In this case it is, apparently, 1.