Every time I try to run this code I get those two errors. I don't see any missing semi-colons or anything? There are no other errors besides those two so I don't know what's going on. My math calculations might be wrong and I can't even compile to check how the program runs! Please help.
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
usingnamespace std;
//function prototype
double MedianF (int *, int);
void arraySort (int *, int);
int main ()
{
int *MyArray = nullptr;
int elements;
double MEDIAN;
cout << "How many elements?" << endl;
cin >> elements;
MyArray = newint[elements];
MEDIAN = MedianF (MyArray, elements);
cout << "The median is..." << MEDIAN << endl;
delete [] MyArray;
MyArray = nullptr;
system("pause");
return 0;
}
double Median (int *Array, int Elem)
{
double median = 0.0;
// First of all, sort our numbers.
arraySort(Array, Elem);
int mid = 0;
// If array is even number of elements, find the middle element
// Size of array split in 2, since it is converted to int, it drops fraction
// subtract 1 because array is zero index.
if((Elem % 2) == 0)
{
mid = (Elem / 2) - 1;
median = (Array[mid] + Array[mid + 1]) / 2;
}
else
{
// If array is odd, find middle term by dividing in half, let it drop
// the fraction when casting ot int. Use middle point to get value.
mid = (int)(Elem / 2);
median = Array[mid];
}
return median;
}
void arraySort (int *Array1, int Elem1)
{
int startScan;
int minIndex;
int minElem;
for (startScan = 0; startScan < (Elem1 - 1); startScan++)
{
minIndex = startScan;
minElem = *(Array1 + startScan);
for (int index = startScan + 1; index < Elem1; index++)
{
if ((*(Array1 + index)) < minElem)
{
minElem = *(Array1 + index);
minIndex = index;
}
}
*(Array1 + minIndex) = *(Array1 + startScan);
*(Array1 + startScan) = minElem;
}
}
Error 1 error LNK2019: unresolved external symbol "double __cdecl MedianF(int *,int)" (?MedianF@@YANPAHH@Z) referenced in function _main C:\Users\Thomas\Documents\C++ practice\Function Median Pointers\Function Median Pointers\Source.obj Function Median Pointers
Error 2 error LNK1120: 1 unresolved externals C:\Users\Thomas\Documents\C++ practice\Function Median Pointers\Debug\Function Median Pointers.exe Function Median Pointers