CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2008
    Posts
    6

    selection sorting

    Hi, I'm making a program that's meant to take 20 names from a user, sort them into alphabetical order using selection sorting, and output the names in order. I decided to make the problem a little simpler by using numbers first instead. So it takes twenty numbers from the user, puts them in order, and then outputs the numbers in the correct order. (You get the idea)

    However, I'm running into problems. I fixed the program in Visual Studio to the point that all my errors went away, but now I'm getting new errors saying:

    "1>c:\users\spenser\documents\visual studio 2005\projects\sortnames\sortnames\sorting.cpp(54) : error C2556: 'void Swap(int [],int,int)' : overloaded function differs only by return type from 'int Swap(int [],int,int)'
    1> c:\users\spenser\documents\visual studio 2005\projects\sortnames\sortnames\sorting.cpp(7) : see declaration of 'Swap'
    1>c:\users\spenser\documents\visual studio 2005\projects\sortnames\sortnames\sorting.cpp(54) : error C2371: 'Swap' : redefinition; different basic types
    1> c:\users\spenser\documents\visual studio 2005\projects\sortnames\sortnames\sorting.cpp(7) : see declaration of 'Swap'"

    I've attached the source code for viewing. I can't see any problems, but obviously something is wrong.

    Scratch that. I just noticed I had function Swap as an int, and then a void later. So yeah. . Now I just need help with my problems switching it over to names.
    Attached Files Attached Files
    Last edited by duskrue; March 28th, 2008 at 06:47 PM.

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: selection sorting

    Quote Originally Posted by duskrue
    I've attached the source code for viewing. I can't see any problems, but obviously something is wrong.
    The error is obvious:
    Code:
    int Swap(int [], int, int);
    //...
    void Swap (int array[], int j, int k)
    The Swap function is declared as returning an int, but in the implementation, it returns void.

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Mar 2008
    Posts
    6

    Re: selection sorting

    Yeah, I saw that and edited the post.

    I altered the code to take names instead, and I'm not getting any errors with that. The problem that the compiler obviously won't pick up is that when it does out put the names, they aren't in order.

    The updated code is in the attachment below.
    Attached Files Attached Files

  4. #4
    Join Date
    Mar 2008
    Posts
    6

    Re: selection sorting

    I tried switching to bubble sort, but that just gets me more lost having to rewrite stuff.

    Anyone's input would be great

  5. #5
    Join Date
    Mar 2008
    Posts
    7

    Re: selection sorting

    Comparing integers is easy using the < , > or = operators.

    You need to use a string compare (strcmp()) for comparing 2 strings (char arrays). Check the link for an example.

    http://www.cplusplus.com/reference/c...ng/strcmp.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured