Need help with this small program using an array.
Posted on 2006-11-08
I'm making this small program that generates 3 randon integers and displays them.
Then it's suppose to sort them and display them letting me know which one is in what element.
I've been working on this trying to follow some book examples, but I'm very lost in the function that sorts them so I can display them back in MAIN()
I must have left out a couple of things or not put the correct commands obviously, if you could please let me know what and where I need to change things.
I want to do this in the most basic way possible, not using other sophisticated ways or commands, cause I'm just learning this as of now.
Thank you for your help.
using namespace std;
unsigned int numarray;
for(a = 0; a < 3; a++)
numarray[a] = rand()% 3;
int temp, elems = 0;
swap = false;
for (int count = 0; count < (elems - 1); count++)
if (numarray[count] > numarray[count +1])
temp = numarray [count];
numarray[count] = numarray[count+1];
numarray[count +1] = temp;
swap = true;
} while (swap);
int main (void)
cout << numarray <<" "<< numarray <<" " << numarray << endl;
cout << "\nThe 1st element is " << numarray;
cout << "\nThe 2nd element is " << numarray;
cout << "\nThe 3rd element is " << numarray;