### help me

hi,i write this program to sort 7 numbers,tell me my mistake.

 ``12345678910111213141516171819202122232425262728293031`` `````` #include using namespace std; void milad(double * a,double * b) { if (a>a[i];} for(i=0;i<7;i++) { for(j=i;j<7;j++) milad(&a[i],&a[j]); } for(i=0;i<7;i++) { cout<
one thing that immediately sticks out (but there's more stuff wrong I reckon) is

 `` `` ``if (a

you are comparing the pointers, not the values that they hold.
ok,i fix this error but this program have runtime error,why?
line 19 makes no sense.

what are you trying to achieve? It looks like you are trying to do a strange mix of populating your array and getting user input.
you also don't initialise your 'c' pointer inside your milad() function.
Last edited on
In fact, why does c need to be a pointer at all?
in fact, why any pointers at all?

 ``123456789101112131415161718192021222324252627282930313233343536373839`` `````` int main() { double a[7]; // some test data a[0] = 4; a[1] = 2; a[2] = 11; a[3] = 65; a[4] = 12; a[5] = 76; a[6] = 1; bool bSwapped(true); double temp(-1); for(int i = 1; (i <= 7) && bSwapped; i++) { bSwapped = false; for (int j=0; j < (7 -1); j++) { if (a[j+1] < a[j]) { temp = a[j]; a[j] = a[j+1]; a[j+1] = temp; bSwapped = true; } } } // display array elements here. return 0; } ``````
Seriously, why use double instead of int?
 Seriously, why use double instead of int?

Erm... presumably because the OP wanted to sort floating-point numbers, rather than integers?

I fail to see how it makes any difference to solving the problem. The solution would be no different for ints.
Topic archived. No new replies allowed.