String Sorting Program Help

I need to create a program that takes the names array and uses a selection sort on the names in the array. This program I created is giving me some trouble and errors and I don't exactly understand what's wrong. I need more sets of eyes to take a look at it.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
 #include <iostream>
#include <string>

using namespace std;

//Sort Function Prototype
void arraySort(string, const int);

//Array Size
const int NUM_NAMES = 20;

int main()

{

    string names[NUM_NAMES] = {"Collins, Bill", "Smith, Bart", "Allen, Jim", "Griffin, Jim", "Stamey, Marty",
                               "Rose, Geri", "Taylor, Terri", "Johnson, Jill", "Allison, Jeff", "Looney, Joe", "Wolfe, Bill", "James, Jean",
                               "Weaver, Jim", "Pore, Bob", "Rutherford, Greg", "Javens, Renee",
                               "Harrison, Rose", "Setzer, Cathy", "Pike, Gordon", "Holland, Beth"};

    //Array Sort Function Call
    arraySort(names, NUM_NAMES);



}


//Array Sort function
void arraySort(string names[], const int NUM_NAMES)
{
    int startScan, minIndex, minValue;

    for (startScan = 0; startScan < (NUM_NAMES - 1); startScan++)
    {
        minIndex = startScan;
        minValue = names[startScan];
        for (int index = startScan + 1; index < NUM_NAMES; index++)
        {
            if (names[index] < minValue)
            {
                minValue = names[index];
                minIndex = index;
            }
        }
        names[minIndex] = names[startScan];
        names[startScan] = minValue;
    }
}
What kind of trouble? Please post the error messages exactly as they appear in your development environment.

26|error: could not convert '(std::string*)(& names)' from 'std::string* {aka std::basic_string<char>*}' to 'std::string {aka std::basic_string<char>}'|

41|error: cannot convert 'std::string {aka std::basic_string<char>}' to 'int' in assignment|

44|error: no match for 'operator<' (operand types are 'std::string {aka std::basic_string<char>}' and 'int')|

46|error: cannot convert 'std::string {aka std::basic_string<char>}' to 'int' in assignment|

Bold = line number
For the first error your function prototype doesn't exactly match the function implementation.

Next for line 41: what type of variable is minValue? What type of variable is names[index]? What exactly are you trying to do on that line? Remember you can't assign a string to an int, or an int to a string.

Topic archived. No new replies allowed.