sort an array using a function

Please help! i have an assignment due for tomorrow. This is what i have been asked to do,

1) Creates an array containing 100 random double numbers in the [0,250) range;
2) Sorts them in descending order;
3) Prints the contents of the sorted vector out. The sorting should be coded as a separate function double* sort_array(double* ).

This is my attempt at it but an error is coming up
" undefined reference to 'sort_array(int*)' "
Any idea why this is happening?


#include <iostream>
#include <cstdlib>

using namespace std;

int randomnumbersarray[100];
double sort_array();

int main()
{
double sort_array(int* nums);
int nums[100], p, q, t, size=100;

for (p=1; p<size; p++) {
for (q=size-1; q>=p; q--) {
if (nums[q-1] < nums[q]) {
t = nums[q-1];
nums[q-1] = nums[q];
nums[q] = t;
}
}
}




{
int randomnumbersarray[100], h;

for (h=0; h<100; ++h) {
randomnumbersarray[h] = (double)(rand()%250);

cout << randomnumbersarray[h] << " ";
}

}
sort_array(randomnumbersarray);

return 0;

}

Im only learning c++ so any help would be great!
Creates an array containing 100 random double numbers
int randomnumbersarray[100];
when i change is from int to double an error: " invalid types 'double [100][double]' for array subscript " ? what could be causing that? i am new to programming and just can't figure out what's wrong! any other advice? :/
There's lots of things wrong with it, I went a head and fixed your formatting and posted it in code tags. For future reference, wrap all your code in code tags "[ code ] [ /code ]" (without the spaces).

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
37
38
39
#include <iostream>
#include <cstdlib>

using namespace std;

int randomnumbersarray[100];
double sort_array();

int main()
{
	double sort_array(int* nums);
	int nums[100], p, q, t, size=100;

	for (p=1; p<size; p++) {
		for (q=size-1; q>=p; q--) {
			if (nums[q-1] < nums[q]) {
				t = nums[q-1];
				nums[q-1] = nums[q];
				nums[q] = t;
			}
		}
	}


{
int randomnumbersarray[100], h;

for (h=0; h<100; ++h) {
	randomnumbersarray[h] = (double)(rand()%250);

	cout << randomnumbersarray[h] << " ";
}

}
sort_array(randomnumbersarray);

return 0;

}


You never actually defined the function sort_array, looks like you copy pasted some of your code in the wrong place. move the code from lines 37 to 41 to the end of your main function and the code from line 11 what was line 26, also remove the semicolon from the end of it.
That reminds me of http://cplusplus.com/forum/beginner/85701/
Are you in the same class ?
could be, its a big enough lecture! do you have any advice?? the error just keeps coming up! :(
Topic archived. No new replies allowed.