arrange variables in array

Hello everyone. Kindly, i need some help for my assignment. So, assume that i have 4variables with constant value, how i'm going to arrange them? So, this is my coding but it doesnt work well.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream.h>
#include <conio.h>
main ()
  {
   int a=5,b=2, c=3, d=1;
   int number[4]={a,b,c,d};
   int i, index, order;

   for (index=0; index<4; index++)
   {
    If (number[index]=number[index+1]
    {
     order=number[index];
     number[index]=number[index+1];
    }
   }
  }
  for (index=0; index<4; index++)
  {
   cout<<order;
  }
What is the purpose of order?

Each time through your first loop number[index]=number[index+1] is something that will never happen since you know they are all different values so trying to assign order=number[index]; is pointless and order continues to hold garbage.

Your second loop just prints the garbage from order 4 times.

I assume you are trying to sort the numbers some how, but how? Maybe take a look at this: http://www.cprogramming.com/tutorial/computersciencetheory/sortcomp.html
Topic archived. No new replies allowed.