dear all!!!
here is my code. when I run it "enter name and enter city "appears together.
I dont understand why. please help me figure it out.
thank you.

#include <iostream>
#include <string>

using namespace std;

void prompt(string name[7], char city[7]);
void init(int index[7]);
void sort(string name[7], int index[7]);
void output(string name[7], char city[7], int index[7]);

int main()
{
    string name[7];
    char city[7];
    int index[7];

    prompt(name, city);
    init(index);
    sort(name, index);
    output(name, city, index);
}

void prompt(string name[7], char city[7])
{
    for(int i=0;i<=6;i++)
    {
        cout << "Please enter name: ";
        cin >> name[i];
        cout << "Please enter city: ";
        cin >> city[i];
    }
}

void init(int index[7])
{
    for(int i=0;i<=6;i++)
    {
        index[i]=i;
    }

}

void sort(string name[7], int index[7])
{
    int i, j;
    for(i=0;i<=5;i++)
    {
        for(j=i+1;j<=6;j++)
        {
            int temp;

            if(name[index[i]] > name[index[j]])
            {
                temp = index[i];
                index[i] = index[j];
                index[j] = temp;
            }
        }
    }
}

void output(string name[7], char city[7], int index[7])
{
    int i;
    cout << endl;

    for(i=0;i<=6;i++)
    {
        cout << name[index[i]] << "        "
            << city[index[i]] << endl;
    }

    cin.ignore();
    cin.get();

    //system("pause");
}

Edited 3 Years Ago by Dani: Formatting fixed

This article has been dead for over six months. Start a new discussion instead.