Can someone PLEASE help me w/ my latest c++ program (compile problems)

Discussion in 'OT Technology' started by MP, Jun 1, 2004.

  1. MP

    MP New Member

    Joined:
    Sep 10, 2002
    Messages:
    34,377
    Likes Received:
    0
    Location:
    Silicon Valley
    here's the code...

    Code:
    /*
    
    title: namelist.cpp
    Project: Create a namelist processor
    description: Maintain and search a list of names
    
    */
    
    #include <iostream>
    using namespace std;
    
    void menu();					// List the users choices
    void add(string, string[], int&);		// Put a new nameon the list
    void remove(string, string[], int);		// Removes name from the list
    void search(string, string[], int);		// Searches for a name from the list
    void showall(string[], int);			// Shows all the names on the list
    
    int main()					// command processing loop
    {
        int currentsize = 0;
        string cmd, newname;
        string list[20];				// An array for adding people to the list
        
        for ( ; ; )
        {
            menu();
            cout << "Enter command: ";
            getline(cin, cmd);
            
            if(cmd == "stop")
            break;
            else if(cmd == "add")
            {
                cout << "New name: ";
                getline(cin, newname);
                add(newname, list, currentsize);
                cout << "The list now has " << currentsize << " names" << endl;
            }
            
            
    //*****Removing a name from the list*****//        
            else if(cmd == "remove")
            {
                cout << "Enter name to be deleted: " ;
                getline(cin, newname);
                remove(newname, list, currentsize);
            }
            
            
    //*****Searching a name in the list*****//
            else if(cmd == "search")
            {
                cout << "Enter name: " ;
                showall(list, currentsize);
                getline(cin, newname);
                cout << "==>" << search(newname, list, currentsize) << endl;
            }
            
    //****Show all the names on the list*****//
            else if(cmd == "showall")
            showall(list, currentsize);
        }
        
        cout << "Thanks for using my program mang! " << endl;
    }
    
    //*****Main Menu*****//
    void menu()
    {
        cout << "Choices===========================" << endl;
        cout << "add ->	Puts a new name in the list" << endl;
        cout << "remove ->	removes a name from the list" << endl;
        cout << "search ->	looks for a specific name" << endl;
        cout << "Stop ->	quits the program" << endl;
        cout << "Choices===========================" << endl;
    }
    
    
    //***** code that adds the name to the list*****//
    void add(string newname, string namelist[], int& currentsize)
    {
        if(currentsize < 20)
        {
            namelist[currentsize] = newname;
            currentsize++;
        }
        else
        cout << "Ohh noes!! To many people on yo list nigga" << endl;
    }
    
    
    //***** Code that removes a name from the list *****//
    void remove(string keyname, string namelist[], int currentsize)
    {
        int k;
        
        for(k = 0; k< currentsize; k++)
        if(keyname == namelist[k])
        {
            cout << "Removing " << keyname << " at location " << k << endl;
            namelist[k] = "Purged";
        }
    }
    
    
    //***** Code that searches for a name on the list *****//
    string search(string keyname, string namelist[], int currentsize)
    
    {
        int k;
        
        for(k = 0; k < currentsize; k++)
        if(keyname == namelist[k])
        return namelist[k];
        return keyname + " Not found";
    }
    
    
    //***** Code for displaying the entire list *****//
    void showall(string namelist[], int currentsize)
    {
        int k;
        
        for(k = 0; k < currentsize; k++)
        cout << "List[" << k << "] = " << namelist[k] << endl;
    }
    
    }
    

    when I try to compile it I'm getting a really really wierd error.

    here's just a snippet of the error.


    it'll go on saying similar stuff for a few PAGES. God damnit I've been trying to figure out what's wrong for a few days now because I didn't wanted to ask something that is problbably really stupid but I have no other choice. I've gone over it many times and cannot figure out what I've done worng :(

    any help would be appreciated
     
  2. MP

    MP New Member

    Joined:
    Sep 10, 2002
    Messages:
    34,377
    Likes Received:
    0
    Location:
    Silicon Valley
    okay, I don't know why there are two threads. I only made one and someone moved it.

    it wasn't me!!
     
  3. skinjob

    skinjob Active Member

    Joined:
    Jan 6, 2001
    Messages:
    2,337
    Likes Received:
    0
    Location:
    Aztlán
    It's trying to tell you that the ostream << operator doesn't know how to handle a void. Notice that you've defined the search function to have no return value, yet it seems like you're expecting one when you use it in a line like

    cout << search(newname, list, currentsize);
     
  4. TheDarkHorizon

    TheDarkHorizon \xC0\xFF\xEE

    Joined:
    Sep 26, 2002
    Messages:
    2,396
    Likes Received:
    0
    Location:
    San Francisco, CA
    Yeah. Your function prototype for search is void, but in your function it is a string.
     
  5. MP

    MP New Member

    Joined:
    Sep 10, 2002
    Messages:
    34,377
    Likes Received:
    0
    Location:
    Silicon Valley
    what would you suggest I change the search too? This is just my first basic program so I'm not all that familiar w/ c++. Still trying to get a grasp of objects and classes.
     
  6. skinjob

    skinjob Active Member

    Joined:
    Jan 6, 2001
    Messages:
    2,337
    Likes Received:
    0
    Location:
    Aztlán
    What did you intend the following line to output when the search succeeds and when the search fails?

    cout << "==>" << search(newname, list, currentsize) << endl;

    Typically, I would want a simple search function to return a yes or no (true or false) whether a piece of data I'm concerned with is contained in the collection of data I'm searching. So something like...

    bool search(string, string[], int);

    then later...

    if (search(newname, list, currentsize) == true)
    {
    cout << newname << " found in list" << endl;
    }
    else
    {
    cout << newname << " not found in list" << endl;
    }
     
  7. MP

    MP New Member

    Joined:
    Sep 10, 2002
    Messages:
    34,377
    Likes Received:
    0
    Location:
    Silicon Valley
    yeah that makes a more sense :hs:

    thanks :)
     
  8. sam758

    sam758 OT Supporter

    Joined:
    Aug 26, 2003
    Messages:
    901
    Likes Received:
    0
    just curious, are you required to create your own list implementation? cuz a lot of the code you wrote for search, add, remove are already provided for u in the stl library.
     
  9. MP

    MP New Member

    Joined:
    Sep 10, 2002
    Messages:
    34,377
    Likes Received:
    0
    Location:
    Silicon Valley
    my teacher hasn't gone over the stl library stuff :-/
     
  10. TheDarkHorizon

    TheDarkHorizon \xC0\xFF\xEE

    Joined:
    Sep 26, 2002
    Messages:
    2,396
    Likes Received:
    0
    Location:
    San Francisco, CA
    I thought the problem was that you declared your function prototype as:
    void search(string, string[], int);
    and your function was later declared as:
    string search(string keyname, string namelist[], int currentsize)
     
  11. z06

    z06 New Member

    Joined:
    May 27, 2003
    Messages:
    141
    Likes Received:
    0
    void main()
    void search(blah blah)
     
  12. diranged

    diranged New Member

    Joined:
    Nov 30, 2003
    Messages:
    2,399
    Likes Received:
    0
    told ya u should have taken Java :)
     
  13. MP

    MP New Member

    Joined:
    Sep 10, 2002
    Messages:
    34,377
    Likes Received:
    0
    Location:
    Silicon Valley

    hehe :mb:
     

Share This Page