Help I'm trying to learn sorting array

why does it say that array type '[n]' is not assignable and also it says expression did not evaluate to constant all in line 8
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include<iostream>
#include<stdio.h>
using namespace std;

void Bucket_Sort(int array[], int n) 
{
	int i, j;
	int count[n];
	for (i = 0; i < n; i++) 
	{
		count[i] = 0;
	}
	for (i = 0; i < n; i++)
	{
		(count[array[i]])++;
	}
	for (i = 0, j = 0; i < n; i++) 
	{
		for (; count[i]>0; (count[i])--) 
		{
			array[j++] = i;
		}
	}
}
int main() 
{
	int array[100];
	int num;
	int i;
	cout << "Enter How many Numbers : ";
	cin >> num;
	cout << "\n\n";
	cout << "Enter the" << num << "elements to be sorted:\n";
	for (i = 0; i < num; i++) 
	{
		cin >> array[i];
	}
	cout << "\nThe array of elements before sorting : \n";
	for (i = 0; i < num; i++) 
	{
		cout << " " << array[i];
	}
	cout << "\nThe array of elements after sorting : \n";
	Bucket_Sort(array, num);
	for (i = 0; i < num; i++) 
	{
		cout << " " << array[i];
	}
	cout << "\n";
	system("PAUSE");
	return 0;
}
Last edited on
In C++ array sizes must be compile time constants, in your program n is not a compile time constant. I suggest you consider using a std::vector instead.
Can you please explain more about it?
Topic archived. No new replies allowed.