0

I can't figure out how to get the sort selection working. I have to sort the scores (doubles) from the struct in ascending order.

Here is my code, I will comment where i am getting the errors.

My struct:

struct diveInfo   
{
    string diversName;
    double totalScore;
    double totalScore;
    double diff;
    double scores[NUM_SCORES];
};

My function to sort the scores in ascending order:

void selectionSort(diveInfo *ptr,  int size)
{
    diveInfo temp;

    double minValue;

    int startScan;
    int minIndex;

    for ( startScan = 0; startScan < (size - 1); startScan++)
    {
        minIndex = startScan;
        minValue = ptr[startScan].scores; //keep getting an error here saying type double cannot be assigned to an entity of type double.
        temp = ptr[startScan];

        for (int index = startScan + 1; index < size; index++)
        {
            if ( ptr[index].scores < minValue) 
            {
                temp = ptr[index];
                minIndex = index;
            }

        }
        ptr[minIndex] = ptr[startScan];
        ptr[startScan] = temp;
    }
}
1
  • scores is an array. Do you perhaps want to sort on the totalScore? You do need to think about what you are doing. It should be clear that assigning an array of doubles to a double is not possible. Commented Apr 24, 2013 at 14:22

3 Answers 3

1

scores is array of doubles, you need to specify index in this array to access specific double value.
For example minValue = ptr[startScan].scores[0];

Sign up to request clarification or add additional context in comments.

Comments

1
minValue = ptr[startScan].scores; 

scores is an array of doubles. arrayname acts as a pointer as well. scores is of type double* [precisely one that can point to an array of size NUM_SCORES] You are assigning a double pointer to an int.

Comments

0

You're trying to assign double* (an array of doubles is a double*) to a double.

You can try changing your array of doubles into a vector of doubles. Then you can sort them using std::sort or std::stable_sort.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.