I'm getting some crazy errors while trying to use a function to find the median of a vector. I'm not exactly sure what's causing these errors.
- 'Error 1 error C2601: 'calcMed' : local function definitions are illegal'
The function I'm trying to use is declared as
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
#include <algorithm>
using namespace std;
double calcMed(int, vector<int>& studentScores);
//
double homeworkMed = calcMed(vectorSize, studentScores);
double calcMed(int vectorSize, vector<int>& studentScores)
{
double median;
sort(studentScores.begin(), studentScores.end());
median = studentScores[vectorSize / 2];
return median;
}
I know that it wouldn't work if I had an odd vector but I just want to get this first one working. Any help would be appreciated.
Removed the semicolon on "double calcMed(int vectorSize, vector& studentScores)" and now I'm getting two different errors, both are on the line right after the function name.
Both of the errors occur on the line with the {
double calcMed(int vectorSize, vector<int>& studentScores)
{