Now, at least it runs, but I have a problem with the bolded part. |
No, you don't. Your problem are the lines 29 and 30, as
lastchance pointed out.
Your effective function calls are:
1 2 3
|
sort( nullptr, 0 );
getAverage( nullptr, 0 );
getMedain( nullptr, 0 );
|
In your getMedain() you calculate
middle = num / 2;
You did call the function with a 0 and thus num==0. We can already compute the middle:
middle = 0 / 2;
middle = 0;
0 % 2 == 0, and therefore median is calculated:
median = ( newArray[-1] + newArray[0] ) / 2;
Your function call did give newArray (in getMedain) the value of
nullptr
.
The newArray does not point to element of any array. The newArray is
invalid pointer.
Dereferencing invalid pointer is
undefined behaviour.
Consider yourself lucky that the program merely crashes. It could silently slaughter all the baby seals of the world.
If you would call the function with a valid pointer, then the newArray would (hopefully) point to the first element of an array, but index -1 is still
out of range. An error.
[EDIT]
Another look at the names in the call:
You and compiler see:
1 2 3 4 5 6
|
void sort( double*, int );
int main()
{
// code
sort( ??? ); // What to write here?
|
The only thing that we do (need to) know about the sort() is that it needs two values: a pointer to double(s) and an integer. There is nothing about names. Only the types.
You have an another function call in your program:
system( "pause" );
How come you can call that function with a literal value rather than with a variable that is named identically to the name of the argument that the implementation of function system() does use?