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.
#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;
}
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.