i posted a similar thread a few days ago re: this program, but i can't get it to work with functions so i'm giving up on them.
i need to write a program that asks a user for a specific number of names, then asks for the names, (last first) then sorts them by last name and displays them by first. then it asks for a search string that checks for a first name in the array. i have started it, but have no idea how to do the sorting section and my search section is acting screwy. can anyone help?

#include <iostream>
#include <string>
using namespace std;

int main( ) {
    //declarations
    int ans;
    int num;
	int i,j;
    char lastname[10][51];
    char firstname[10][51];
    char lastnametemp[10][51];
    char firstnametemp[10][51];
    char query[51];

    //ask for number of names
    cout<<"Enter number of names."<<endl;
	cin>>num;

    //ask for names
    cout<<"Enter names."<<endl;
    for(i=0;i<num;i++){
        cin>>lastname[i];
        cin>>firstname[i];
    }
    
    //sort names

    //display names in the form, "first last"
    for(i=0;i<num;i++)
        cout<<firstname[i]<<" "<<lastname[i]<<endl;

    //search names
    cout<<"Enter first name to locate."<<endl;
    cin>>query;
    
    for(i=0;i<num;i++){
        for(j=0;j<51;j++){
            if(query[j]==firstname[i][j]){
                if(firstname[i][j]=='\0'){
                    cout<<"The name IS in the list."<<endl;
                    break;
                }
                else
                    continue;
            }
            else{
                cout<<"The name is NOT in the list."<<endl;
                break;
            }
        }
    }

    system("PAUSE");
    return 0;
}

Looks like someone still hasn't read the Rules yet. And this is also very helpful.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.