#Cannot use 'divide' binary operation in accumulate function...

18 messages · Page 1 of 1 (latest)

buoyant hollowBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

amber flax
#

what seems to be the problem exactly

#

"can't use" is a very vague statement

#

Im assuming you're having issue with the integer division

crisp helm
#

100/1 -> 100
100/2 -> 50
50/3 -> 16
16/4 -> 4
4/5 -> 0

#

it's doing integer division operations that round

coarse jay
#

maybe they are on windows and didn't include <functional>

#

which would be a compile error

#

on gcc iirc it compiles but then there's the whole integer division thing

#

include <functional>

buoyant hollowBOT
amber flax
#

yeah divides is in <functional> not <numeric>

crisp helm
#

;compile

#include<iostream>
#include<vector>
#include<numeric>
#include<functional>

int main() {
    std::vector<int> terms{ 1, 2, 3, 4, 5 };

    float eval = std::accumulate(terms.begin(), terms.end(), 100.F, std::divides());

    std::cout << eval << std::endl;

    return 0;
}
low treeBOT
#
Program Output
0.833333
coarse jay
#

request msvc_x64_latest or whatever

crisp helm
#

/solved

coarse jay
#

ermh, !solved? I don't remember

buoyant hollowBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity