I am having trouble finishing this code for an assignment i have due. I have to create a code that (depending on what the user picks) sorts the numbers in ascending or decending order using an array with the funcion in the code. Any help would be greatly appriciated.

    #include <iostream>
    using namespace std;

    void sortMe(int array[],int sortedIndexes [], int size, char mode);

    int main()
    const int size=10;
    int array[size]={8,2,7,4,10,-1,0,3,9,5};
    int sortedIndexes[size];
    int sortMe;
    char mode;

    cout<<"Please press (a) for ascending or (d) for decending order."<<endl;

    if (mode=='a')
        for(int i=0;i<size-1;i++)
        system ("pause");

Recommended Answers

All 2 Replies

I'll point out the obvious. One, this doesn't compile. Two, sortMe is not written. Am I correct in assuming that this is the code you have been GIVEN and the task is to change it so things work? If so, you're going to have to ask a specific question and show effort. Otherwise it's considered a homework dump.

A good start would be to write a sortMe function that does nothing but print out that it was called as a temporary debugging mechanism. Then write some code that actually calls the function with the right parameters, particularly the mode. Then look at line 19. You have a for-loop that goes through an array. Looks like something that is part of a sort, so stick it in your sorting function and finish writing the sorting code there, not in main. Finally, what is sortedIndexes[]? The sorting parameters seem off. Seems like you're passing TWO arrays, not one, to the function. Most sorting procedures have you pass only one. Find out precisely what you're supposed to do with that sortedIndexes.

this will reorganize your array into smallest to largest.
now just out put 0-9 or 9-0 depending on function a or b

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.