Thread: need a second pair of eyes

  1. #1
    Unregistered
    Guest

    need a second pair of eyes

    Im really new (48 hrs) and slowy grasping this stuff.

    I think I have the majority of errors taken care of but Im still getting one that says

    "[Linker error] undefined reference to 'number_sort(int *, int)'

    If anyone feels like helping, I would really appreciate it. Feel free to tear it apart but please try to go slow as I still dont understand much.

    Code:
    #include <iostream>
    
    using std::cout;
    
    using std::cin;
    
    
    void number_sort(int array[], int maxnum);
    
    int main(void)
    {
        // DECLARE VARIABLES
        
        int maxnum;  // This is how many numbers we will be using
        
        int ToBeSorted;  // Values which will eventually be in ascending order
        
        int Array[100]; // Declare Array with no more than 100 elements
        
        int Copied; // If value is < than ToBeSorted Value then copy value to Storage
        
        int Storage;  // This holds values temp until copy is complete
        
    	
        cout << "How many numbers do you want to sort? ";
        
        cin >> maxnum;
        
        cout << "\nPlease begin entering " << maxnum << " numbers.\n";
        
        ToBeSorted = 1;
        
    
    	// GATHER DATA		
    	
    		for(ToBeSorted = 1; ToBeSorted < maxnum + 1; ToBeSorted++){  
    
    		    /* 
    		    
    			Use ToBeSorted as the array subscript and loop until we have all numbers needed (maxnum).
    			
    			"ToBeSorted" is set to 1 for the first number entered and since we increased ToBeSorted by
    			
    			one, the same must be done to "maxnum"
    			
    			*/
    
    
           		cout << "\nEnter number " << ToBeSorted << "\n";
           		
           		cin >> Array[ToBeSorted];  // Initialize array with values
           		
           		cout << "\n";
           		   		
           	}
    
    	// SORTING
    
    		number_sort(Array, ToBeSorted);
    
    	// DISPLAY
    
    		for(ToBeSorted = 1; ToBeSorted < maxnum + 1; ToBeSorted++){  
    		
    			cout << Array[ToBeSorted] << "\n";
    			
    		}
    		
    }
    
    void nubmer_sort(int array[], int maxnum)
    {
        
        int ToBeSorted;  // Values which will eventually be in ascending order
        
        int Array[100]; // Declare Array with no more than 100 elements
        
        int Copied; // If value is < than ToBeSorted Value then copy value to Storage
        
        int Storage;  // This holds values temp until copy is complete
        
    
        for(ToBeSorted = 1; ToBeSorted < maxnum + 1; ToBeSorted++){  // Loop until we reach final value
    
            for(Copied = ToBeSorted+1; Copied < maxnum + 1; Copied++){  // Loop again and move values if needed
    
                if(Array[ToBeSorted] > Array[Copied]){  // if ToBeSorted(1) is greater than Copied(2) then do next 3 lines
    				
    					Storage = Array[ToBeSorted];  // Move ToBeSorted into temp Storage
    					
    					Array[ToBeSorted] = Array[Copied]; // Move the smaller number from Copied to the ToBeSorted array
    					
    					Array[Copied] = Storage; // Now copy the original value we got from ToBeStored (now in Storage) to the Copied array
                }
            }
        }    
    }

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Your number_sort function is conflicting with another function which has the same name and same parameters. This causes the compiler to choke. Try changing the name of the sort function or prefix the declaration and definition with static and it should work okay, but it doesn't sort properly.

    [edit]
    Doh, the first thing I did when pasting this code is copy the declaration into the definition. Then I did my checking. How's that for habit? ;p
    [/edit]

    -Prelude
    Last edited by Prelude; 06-27-2002 at 11:35 AM.
    My best code is written with the delete key.

  3. #3
    Unregistered
    Guest

    LOL

    it was a simple typo...

    when I had that function in the main() it worked... now I need to go find out why its not when I made it a function.

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >void nubmer_sort(int array[], int maxnum)

    Notice how number is misspelled. Try:
    void number_sort(int array[], int maxnum)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Polynomials and ADT's
    By Emeighty in forum C++ Programming
    Replies: 20
    Last Post: 08-19-2008, 08:32 AM
  2. Need an extra pair of eyes ....
    By Whoputthatthere in forum C Programming
    Replies: 5
    Last Post: 06-02-2006, 12:19 PM
  3. Writing my own stl container
    By curos in forum C++ Programming
    Replies: 10
    Last Post: 12-18-2005, 04:33 AM
  4. need another pair of eyes please
    By dustyd in forum C++ Programming
    Replies: 4
    Last Post: 01-23-2003, 03:12 PM
  5. need a second pair of eyes to debug
    By RyeDunn in forum C Programming
    Replies: 7
    Last Post: 08-02-2002, 10:02 AM