I'm a bit new to c++ and I was trying to make a function that essentially adds the values given by another function for integer value inputs from the range start
to end
int sum(int start, int end, int function(int input)){
int output=0;
for(int i=start; i<end; i++){
output=output+function(i);} //add the elements of the function from start to end
return output;}
the above piece of code was the piece of code that I tried to run in visual studios but whenever I assign the variables some real values I get errors like type int incompatible with parameters of int(*)int(input)
or something like that...I tried to get some help from the internet but most sources give very complicated code without really explaining how the code works...so I'd like to know how to do this and the reason behind why the way I did it doesn't work...using as little code as possible...and any explanation as to why an answer code would work will be appriciated as well...thanx a million in advance
edit: the function can be any function and the sum function takes in in the inputs given by the for loop, applies to the function and adds the values together...for example
int function(x){ return 2*x;}
//output to function(3)=6;
//output to the sum(1,5,function(x))=2+4+6+8=10...(or at least thats what I want it to equal