I am having problems using the accumulate to find the sum of all elements in a vector. Here is what I have:
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <istream>
#include <string>
#include <vector>
#include <numeric>
using namespace std;
int main()
{
vector<float> energy;
for(int i = 0; i < 25; i++)
energy.push_back(5.364*i);
float sum = accumulate(energy.begin(),energy.end(),0);
cout << "Sum: " << sum << endl;
};
I would like this program to calculate the sum of all elements in the energy vector. When I try to compile, I get a list of about 50 errors relating to the numeric header file. Can somebody tell me whats wrong with my code please.