sort ints in an array

Im trying to sort rand generated ints in an array from greatest to least but i dont know how. im still pretty new to this and most of what i have already i got from reading posts here. i cant seem to find anything else that can help so im kinda stuck.

1
2
3
4
5
6
7
8
9
10
11
12
int* humFight(int humDice)
{
	int* a=new int[humDice];
	int rolled=0;
	srand (time(NULL));
	while(rolled<humDice)
	{
		a[rolled]=(rand()%6)+1;
		rolled=rolled++;
	}
	return a;
}
Google search bubble sort
i now have
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
int* humFight(int humDice)
{
	int* a=new int[humDice];
	int rolled=0;
	srand (time(NULL));
	while(rolled<humDice)
	{
		a[rolled]=(rand()%6)+1;
		rolled=rolled++;
	}
	
    int i,j;
    for(i=0;i<sizeof(a);i++)
    {
        for(j=0;j<i;j++)
	{
            if(a[i]>a[j])
            {
                int temp=a[i];
                a[i]=a[j];
                a[j]=temp;
            }

        }

    }

    return a;
Last edited on
Topic archived. No new replies allowed.