warning C4067: unexpected tokens following preprocessor directive - expected a newline

Aug 21, 2014 at 2:10am
Hey guys. Please help take a look at my code below. didn't build successfully and I couldn't figure out why...


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
  #include <iostream>

#include <algorithm>
#include <string>
#include <conio.h>
#include "xmedian.h"
using namespace std;

int main()
{
	vector<double> test;
	test.push_back(0);
	test.push_back(1);
	double med=median(test);
	cout<<med<<endl;

	cout << "Press enter to continue...";
    _getch();
	return 0;

}

#ifndef GUARD_xmedian.h
#define GUARD_xmedian.h
//header file to calculate the median of a vector

#include <vector> 
using namespace std; 
double median(vector<double>);


#endif

-------

#include "xmedian.h"
#include <algorithm>
#include <stdexcept>
//#include <vector>
//using namespace std;
//probably we don't need using namespace std?
double median(vector<double> vec)
{
	typedef vector<double>::size_type vec_sz;
	vec_sz size=vec.size();
	if (size==0)
	{
		throw domain_error("median of an empty vector");
	}
	sort(vec.begin(),vec.end());
	if (size%2==0)
		return (vec[size/2-1]+vec[size/2])/2;
	else
		return vec[size/2];

}

Aug 21, 2014 at 2:11am
the left is the main function

right above is the median header file
right below is the median source file.

Any help would be appreciated!
Aug 21, 2014 at 2:20am
Figured out my mistake. Should be x_median_h

Topic archived. No new replies allowed.